JavaScript DOM操作案例点击图片修改宽和高
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title></title> 6 </head> 7 <body> 8 <img src="images/liuyan.jpg" alt="" id="im"/> 9 <script> 10 //通过id获取图片元素,注册点击事件,添加事件处理函数 11 document.getElementById("im").onclick = function () { 12 //修改自身的width属性值 13 this.width = "200"; 14 //修改自身的height属性值 15 this.height = "300"; 16 }; 17 </script> 18 </body> 19 </html>