zno2

element onclick 动态创建元素并绑定onclick事件

 

<html>
<head>
    <meta charset="UTF-8">
    <title>b</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript">
        
        function ff(){
            var img = document.createElement("img");
            img.src = "https://tomcat.apache.org/images/tomcat.png";
            img.onclick = function(){
                show(this)    
            };
            
            $("body").append(img);
        }
        
        function show(obj){
            alert(obj.src);
        }
    </script>
</head>
<body>
    <span onclick="ff()">胜多负少</span>
</body>
</html>

 

posted on 2016-08-05 18:15  zno2  阅读(780)  评论(0编辑  收藏  举报

导航