如何用JS实现,单击图片,在新的页显示图片

JavaScript09

如何用JS实现,单击图片,在新的页显示图片,第1张

<img src="http://img.baidu.com/img/iknow/avarta/66/r11s1g5.gif" onclick="window.open(this.src,'_blank')"/>

onclick 点击图片事件

window.open('','') 打开一个新网页 第一个参数是网址 第二个是打开方式

window.open(this.src,'_blank') 以该图片的路径为网址,以新页的方式打开

这篇文章主要介绍了js实现单击图片放大图片的方法,涉及javascript操作图片的技巧与onclick事件的用法,需要的朋友可以参考下

本文实例讲述了js实现单击图片放大图片的方法。分享给大家供大家参考。具体实现方法如下:

代码如下:

<html>

<title>单击图片即可放大图片</title>

<body>

点击图片预览效果。<br>

<img

src="/images/m01.jpg"

onclick="this.width+=50this.height+=50"

onclick="javascript:window.open(this.src)"

style="cursor:pointer"/>

<img

src="/images/m02.jpg"

onclick="this.style.zoom='2'"

onclick="javascript:window.open(this.src)"

style="cursor:pointer"/>

</body>

</html>

希望本文所述对大家的javascript程序设计有所帮助。

<!doctype html>

<html>

<head>

<meta charset="UTF-8">

<meta name="Generator" content="EditPlus®">

<meta name="Author" content="">

<meta name="Keywords" content="">

<meta name="Description" content="">

<title>Document</title>

<script src="jquery-3.1.1.min.js"></script>

</head>

<body>

<h3>请选择图片文件:JPG/GIF</h3>

<form name="form0" id="form0" >

<input type="file" name="file0" id="file0" multiple="multiple" />

<br><br><img src="" id="img0" width="120">

</form>

</body>

<script>

$("#file0").change(function(){

var objUrl = getObjectURL(this.files[0])

console.log("objUrl = "+objUrl)

if (objUrl)

{

$("#img0").attr("src", objUrl)

$("#img0").removeClass("hide")

}

})

//建立一个可存取到该file的url

function getObjectURL(file)

{

var url = null

if (window.createObjectURL!=undefined)

{ // basic

url = window.createObjectURL(file)

}

else if (window.URL!=undefined)

{

// mozilla(firefox)

url = window.URL.createObjectURL(file)

}

else if (window.webkitURL!=undefined) {

// webkit or chrome

url = window.webkitURL.createObjectURL(file)

}

return url

}

$('input').on('change',function(){

var value = $(this).val()

value = value.split("\\")[2]

alert(value)

})

</script>

</html>