JavaScript DOM操作案例点击图片弹出对话框

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title></title>
 6     <style>
 7         img {
 8             width: 200px;
 9             height: 300px;
10         }
11     </style>
12 </head>
13 <body>
14 <img src="images/liuyan.jpg" alt=""/>
15 <img src="images/liuyan.jpg" alt=""/>
16 <img src="images/liuyan.jpg" alt=""/>
17 <script>
18     //获取所有的img标签
19     var imgObjs = document.getElementsByTagName("img");
20     //遍历标签
21     for (var i = 0; i < imgObjs.length; i++) {
22         //注册点击事件,添加事件处理函数
23         imgObjs[i].onclick = function () {
24           alert("柳岩思密达");
25         };
26     }
27 </script>
28 </body>
29 </html>

 

posted @ 2018-07-19 20:48  {颜逸}  阅读(1035)  评论(0编辑  收藏  举报