第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

按鈕5和6都沒反應

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>事件</title>

</head>


<body>

<input type="button" value="按鈕1" onclick="alert('111')"/>

<input type="button" value="按鈕2" onclick="aaa()"/>

<input type="button" value="按鈕3" id="but3"/>

<input type="button" value="按鈕4" id="but4"/>

<input type="button" value="按鈕5" id="but5"/>

<input type="button" value="按鈕6" id="but6"/>


<script type="text/javascript">

//html方法

function aaa(){

alert("222");

}

//DOM0級

var but3=document.getElementById("but3");

but3.onclick=function(){alert("333");};

//DOM2級

var but4=document.getElementById("but4");

but4.addEventListener("click",aaa,false);

//but4.removeEventListener("click",aaa,false);

//IE

var but5=document.getElementById("but5");

but5.attachEvent("onclick",aaa);

//but5.detachEvent("onclick",aaa);

//跨瀏覽器


var eventUtil={

addevent:function(ele,type,hander){

if(ele.addEventListener){

ele.addEventListener(type,hander,false);

}

else if(ele.attachEvent){

ele.attachEvent("on"+type,hander);

}

else{

ele["on"+type]=hander;

//ele.onclick===ele["onclick"];

}

},

removeevent:function(ele,type,hander){

if(ele.removeEventListener){

ele.removeEventListener(type,hander,false);

}

else if(ele.detachEvent){

ele.detachEvent("on"+type,hander);

}

else{

ele["on"+type]=null;

}

}

};

var but6=document.getElementById("but6");

eventUtil.addevent(but6,"click",aaa);

//but6.attachEvent("onclick",aaa);

</script>


</body>

</html>


正在回答

3 回答

//IE

var but5=document.getElementById("but5");

but5.attachEvent("onclick",aaa);

//but5.detachEvent("onclick",aaa);

//跨瀏覽器


這段代碼需要注釋掉。按鈕6就能用,在“//跨瀏覽器”代碼中調(diào)用按鈕5,按鈕5就能用。

1 回復 有任何疑惑可以回復我~
#1

nico_0 提問者

非常感謝!
2016-03-22 回復 有任何疑惑可以回復我~
#2

葉微白_ 回復 nico_0 提問者

IE9,支持這個特性了,現(xiàn)在主流瀏覽器都支持,用戶前五谷歌,IE,火狐,歐朋等均支持addEventListener特性,慕課這個視頻有點年代,老師用的還是XP系統(tǒng)了。建議在慕課學的同時,在w3cschool看下相關知識,上面更新的非常及時。以后,跨瀏覽器問題會越來越少。
2016-03-22 回復 有任何疑惑可以回復我~
#3

葉微白_ 回復 葉微白_

IE8以及以前的老版本支持attachEvent。2016年微軟放棄IE了,window10開始用 Microsoft Edge,以后,隨著windows發(fā)展,IE不再更新,維護。就像XP一樣淘汰。學IT的,多了解下前沿的技術信息。
2016-03-22 回復 有任何疑惑可以回復我~

而且第5個按鈕僅僅是在IE上才支持的,其他瀏覽器是不支持的。

0 回復 有任何疑惑可以回復我~
#1

nico_0 提問者

我的IE瀏覽器更新之后可以支持addEventListener,是不是只有老版本的ie不支持現(xiàn)在的支持了?
2016-03-22 回復 有任何疑惑可以回復我~
#2

丫丫小小笑 回復 nico_0 提問者

好像是IE9以前的不支持addEventListener。。。
2016-03-23 回復 有任何疑惑可以回復我~

//DOM2級

var but4=document.getElementById("but4");

but4.addEventListener("click",aaa,false);

//but4.removeEventListener("click",aaa,false);

//IE

var but5=document.getElementById("but5");

but5.attachEvent("onclick",aaa);

//but5.detachEvent("onclick",aaa);

把這些都注釋掉。。。因為前面寫的這些是會對后面的能力選擇造成錯誤的。

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
DOM事件探秘
  • 參與學習       99532    人
  • 解答問題       1291    個

DOM事件?本課程會通過實例來給小伙伴們講解如何使用這些事件

進入課程

按鈕5和6都沒反應

我要回答 關注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號