在使用IE,attachEvent的時候會報錯啊,求解答
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>事件流</title>
</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/IE" id="btn4" />
<input type="button" value="按鈕5/兼容" id="btn5" />
</div>
<script type="text/javascript">
function showMes(){
alert("hello world");
}
var btn2 = document.getElementById('btn2');
var btn3 = document.getElementById('btn3');
var btn4 = document.getElementById('btn4');
var btn5 = document.getElementById('btn5');
//DOM0級處理程序
btn2.onclick=function(){
alert('這是通過DOM0級添加的事件!');
}
btn2.onclick = null; //刪除onclick屬性
//DOM2級事件
/*btn3.addEventListener('click',showMes,false);
btn3.addEventListener('click',function(){
alert(this.value);
},false);*/
//btn3.removeEventListener('click',showMes,false);//刪除事件處理程序
//IE事件處理程序
btn4.attachEvent('onclick',showMes);
</script>
</body>
</html>
報錯信息:[Web瀏覽器] "Uncaught TypeError: undefined is not a function"
2016-09-11
IE11 添加、更改、刪除了許多默認的傳統功能:
?
navigator.appName?屬性現在會返回 "Netscape" 以反映 HTML5 標準和匹配其他瀏覽器的行為。
navigator.product?屬性現在會返回 "Gecko" 以便反映 HTML5 標準和匹配其他瀏覽器的行為。
XDomainRequest?對象被 XMLHttpRequest 的 ORS 替換。
已添加對 __proto__ 的支持。
已添加?dataset?屬性。
另外,為了支持現行標準指定的功能,已刪除若干傳統 API 功能:
?
刪除 API 功能 ? ?替代功能 ? ?
attachEvent ? ?addEventListener ? ?
window.execScript ? ?eval ? ?
window.doScroll ? ?window.scrollLeft、window.scrollTop ? ?
document.all ? ?document.getElementById ? ?
document.fileSize、img.fileSize ? ?使用?XMLHttpRequest?可提取源 ? ?
script.onreadystatechange?和?script.readyState ? ?script.onload ? ?
document.selection ? ?window.getSelection ? ?
document.createStyleSheet ? ?document.createElement("style") ? ?
style.styleSheet ? ?style.sheet ? ?
window.createPopup ? ?使用?div?或?iframe(zIndex?值很高) ? ?
二進制行為 ? ?變化;使用基于標準的等效,如?canvas、SVG 或 CSS3 動畫 ? ?
傳統數據綁定 ? ?使用框架提供的數據綁定,如 WinJS ? ?
?
?
2017-12-13
所以是attachEvent 已經被刪除了嘛