跨浏览器的事件处理程序

2017-06-16 17:10:00
admin
原创
537
<!DOCTYPE html>
<html>
<head>
    <title>Cross-Browser Event Handler Example</title>
    <script type="text/javascript" src="EventUtil.js"></script>
</head>
<body>
    <input type="button" id="myBtn" value="Click Me" />
    <input type="button" id="myRemoveBtn" value="Remove Event Handler" />
    <script type="text/javascript">
        var btn = document.getElementById("myBtn");
        var handler = function(){
            alert("Clicked");
        };
        EventUtil.addHandler(btn, "click", handler); 
        
        var removeBtn = document.getElementById("myRemoveBtn");
        EventUtil.addHandler(removeBtn, "click", function(){
            EventUtil.removeHandler(btn, "click", handler); 
        });
        
    </script>
</body>
</html>
  • QQ讨论群
  • 关注微信
    • 欢迎咨询
    • 欢迎加入QQ群 16506021
  • 公众号:源宝网络