• event 事件 attachEvent addEventListener绑定事件


    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="UTF-8">
    		<title></title>
    		<script>
    			window.onload = function(){
    				var oBtn = document.getElementById("btn1");
    				
    				//attachEvent(事件名,函数)
    				//IE支持  火狐谷歌不支持
    //				oBtn.attachEvent("onclick",function(){
    //					alert("a");
    //				});
    //				
    //				oBtn.attachEvent("onclick",function(){
    //					alert("b");
    //				});
    				
    				//ff 谷歌
    				//addEventListener(事件名,函数,false/true)false冒泡 true捕捉
    				//和attachEvent的不一样的是:事件不加on
    //				oBtn.addEventListener("click",function(){
    //					alert("a");
    //				});
    //				oBtn.addEventListener("click",function(){
    //					alert("b");
    //				});
    
    				//兼容写法
    				if(oBtn.attachEvent)
    				{
    					//ie下顺序相反 ie的一个bug
    					oBtn.attachEvent("onclick",function(){
    						alert("a");
    					});
    					
    					oBtn.attachEvent("onclick",function(){
    						alert("b");
    					});
    					
    				}else{
    					oBtn.addEventListener("click",function(){
    						alert("a");
    					});
    					oBtn.addEventListener("click",function(){
    						alert("b");
    					});
    				}
    			}
    		</script>
    	</head>
    	<body>
    	<input type="button" value="点击" id="btn1" />
    	</body>
    </html>
    

      

  • 相关阅读:
    Scite 中文支持
    【线段上】简单贪心总结……未完
    Happy new year!
    poj 2960 SNim
    【转】SG函数资料(入门必备)
    poj 2478 Farey Sequence
    Poj 3083 Children of the Candy Corn
    Poj 1077 Eight 八数码
    Poj 1830 开关问题:高斯消元
    关于poj 放苹果
  • 原文地址:https://www.cnblogs.com/mingjixiaohui/p/5269807.html
Copyright © 2020-2023  润新知