<html>
<head>
<title></title>
<meta?charset="utf-8">
</head>
<body>
<div?id="box">
<input?type="button"?value="按鈕"?id="btn"?onclick="showmes()">
<input?type="button"?value="按鈕2"?id="btn2">
<input?type="button"?value="按鈕3"?id="btn3">
<input?type="button"?value="按鈕4"?id="btn4">
</div>
<script>
function?showmes(){
alert("hello?world");
}
//dom?0?級事件
var?btn2?=?document.getElementById("btn2");
btn2.onclick?=?function(){
alert("這是DOM?0?級");
}
btn2.onclick?=?null;
//dom?2級事件?可以加多個事件
//?var?btn3?=?document.getElementById("btn3");
//?btn3.addEventListener("click",showmes,false);
//?btn3.addEventListener("click",function(){
//? alert(this.value);
//?},false);
//?btn3.removeEventListener("click",showmes,false);
//ie?事件處理程序?attachEvent()
var?btn3?=?document.getElementById("btn3");
btn3.attachEvent('onclick',showmes);
</script>
</body>
</html>
2016-05-10
IE版本問題吧 有些只支持dom?0?級事件,有些支持attachEvent(); 把btn3改為dom?0?級事件試試。
2016-05-16
2016-05-10
en ? ie11 不支持attachEvent()