IE事件處理程序在IE中無反應(yīng)
<!DOCTYPE html>
<html>
?? ?<head>
?? ??? ?<meta charset="UTF-8" http-equiv="content-type" content="text/html">
?? ??? ?<title>事件處理程序</title>
?? ??? ?<script type="text/javascript">
?? ??? ?function shows(){
?? ??? ??? ?alert('你好嗎!');
?? ??? ?}
?? ??? ?
?? ??? ?window.onload=function(){
?? ??? ?var btn2=document.getElementById('btn2');??
?? ??? ?btn2.onclick=function()?? ??? ??? ?
?? ??? ?{
?? ??? ??? ?alert('我很好,你呢');
?? ??? ?}?? ???
?? ??? ?btn2.onclick=null; //刪除onclick按鈕屬性
?? ??? ?
?? ??? ?var btn3=document.getElementById("btn3");
?? ??? ??? ?btn3.addEventListener("click",shows,false);?
?? ??? ??? ?btn3.addEventListener("click",function(){alert("你吃飯了沒?");},false);
?? ??? ??
?? ??? ??? ?btn3.addEventListener("click",function(){
?? ??? ??? ??? ?alert(this.value);?? ?//this可以引用被觸發(fā)的元素,后面寫value,執(zhí)行會(huì)顯示按鈕名稱
?? ??? ??? ?},false);
?? ??? ??? ?//btn3.removeEventListener("click",shows,false);??
?? ??? ?var btn4=document.getElementById("btn4");
?? ??? ??? ?btn4.attachEvent("onclick",shows);?? ???
?? ??? ??? ?btn4.detachEvent("onclick",shows);?? ???
?? ??? ?}
?
?? ??? ?
?? ??? ?</script>
?? ?</head>
?? ?<body>
?? ??? ?<input type="button" value="按鈕一"? id="btn1" onclick="shows()" />
?? ??? ?<input type="button" value="按紐二"? id="btn2" />
?? ??? ?<input type="button" value="按紐三"? id="btn3" />
?? ??? ?<input type="button" value="按紐四"? id="btn4" />
?? ?</body>
</html>
錯(cuò)誤信息:"Uncaught TypeError: undefined is not a function"???
是不是ie版本問題
2016-12-11
我的IE下沒有出現(xiàn)同樣的問題