如何处理 JavaScript 中 Internet Explorer 和 addEventListener 问题"对象不支持此属性或方法"?
javascriptobject oriented programmingfront end technology更新于 2024/7/2 18:52:17
要处理 JavaScript 中的"对象不支持此属性或方法"问题,在使用事件和 Internet Explorer 时,请使用此减号更新代码
示例
<html> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge;" /> </head> <body> ... </body> </html>
您也可以使用 IE 中的 attachmentEvent 来解决此问题,如下所示 −
if (ev.addEventListener) {
ev.addEventListener('click', myText, false);
}
else if (ev.attachEvent) {
ev.attachEvent('onclick', myText);
}
相关文章
有用资源
javascript 参考教程 - 该教程包含有关 javascript 的更多信息:https://www.cainiaomax.com/javascript/

