[英]“Object doesn't support method” error when extending Element.prototype in IE8
I understand that IE8 supports extension of the Element
object. 我了解IE8支持
Element
对象的扩展。 I tried a simple example, and it works in Google Chrome but not in IE8. 我尝试了一个简单的示例,它可以在Google Chrome浏览器中使用,但不能在IE8中使用。 Here is my code, and here is a jsfiddle to see my code :
这是我的代码, 这是查看我的代码的jsfiddle :
HTML HTML
<div id='test'>Hi</div>
JavaScript JavaScript的
Element.prototype.test = function(){
alert('yup');
}
document.getElementById('test').test();
Errors 错误
//jsfiddle.net => Object doesn't support property or method 'test'
//local test => 'Element' is undefined
What am I doing wrong? 我究竟做错了什么?
Ok as for the local error, it seems that IE8 didn't like my <!DOCTYPE>
tag. 好的,关于本地错误,看来IE8不喜欢我的
<!DOCTYPE>
标记。 So I found another one. 所以我找到了另一个。 =p IE8 is very strict on things like that.
= p IE8在此类方面非常严格。 If an element isn't valid HTML, IE8 won't pick it up in things such as
document.getElementsByTagName()
. 如果某个元素不是有效的HTML,则IE8不会在
document.getElementsByTagName()
东西中使用它。
MooTools overrides the baseline Element
. MooTools会覆盖基线
Element
。
Check out 查看
var e = document.getElementById('test');
console.log(e instanceof Element);
with MooTools on it returns false, with anything but MooTools it should return true. 如果启用MooTools,则返回false,否则应返回true。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.