1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title></title> 6 </head> 7 <body> 8 <input type="button" value="修改图片属性" id="bt"/> 9 <img src="images/liuyan.jpg" alt="" id="im"/> 10 <script> 11 //通过id获取按钮元素,注册点击事件,添加事件处理函数 12 document.getElementById("bt").onclick = function () { 13 //获取图片元素 14 var imgObj = document.getElementById("im"); 15 //修改alt属性 16 imgObj.alt = "liuyan"; 17 //修改title属性 18 imgObj.title = "柳岩"; 19 }; 20 </script> 21 </body> 22 </html>