日期:2014-05-16 浏览次数:20327 次
// test.js function test(){ var images = document.getElementsByTagName("img"); for(var i=0;i<images.length;i++){ images[i].onclick = function(){ //event state } } }
------解决方案--------------------
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>test</title> </head> <body> <img src="1.jpg"> <img src="2.jpg"> <img src="3.jpg"> <script type="text/javascript"> document.onclick = function(event){ var e = event || window.event, target = e.target || e.srcElement; if(target.tagName === "IMG"){ alert("点击了图片!"); } } </script> </body> </html>