如何用JS语句显示图片?

JavaScript09

如何用JS语句显示图片?,第1张

需要准备的材料分别有:电脑、html编辑器、浏览器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<script>标签,输入js代码:$('body').append('<img src="https://www.baidu.com/img/bd_logo1.png" />')。

3、浏览器运行index.html页面,此时图片被js成功显示到页面上。

<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') 以该图片的路径为网址,以新页的方式打开

<form action="" method="post" enctype="multipart/form-data" name="form1">

<img src=" " name="image" border=0 id="img"/>

<br />

<input name="picture" type="file" id="picture" onchange="img.src=this.value" />

</form>

不需要按钮,直接触发onchange事件就能实现~~~