js代理

时间:2014-05-14 07:42:30   收藏:0   阅读:307
bubuko.com,布布扣
<!doctype html>
<html lang="en">
 <head>
  <title>proxy</title>
  <style>
  img{width:200px;heigth:200px;}
  </style>
 </head>
 <body>
  <div id="aa">
  <img id="img1" src="http://images.cnblogs.com/cnblogs_com/lj915/578797/o_1.jpg">
  <img id="img2" src="http://images.cnblogs.com/cnblogs_com/lj915/578797/o_2.jpg">
  </div>
  <script>
  document.getElementById("aa").onclick = function(e){     
        var target = _getTarget(e);
        if(target.tagName.toLowerCase() == "img") {
            alert(target.id);
        }  
  }
  function _getTarget(event) {      
      return event.target || event.srcElement;
  }
  </script>
 </body>
</html>
bubuko.com,布布扣

 

js代理,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!