[英]IE9: Object doesn't support the property “is”
我正在尝试编写一个小jQuery插件,但是(当然)Internet Explorer 9出现了问题。
这是代码:
$.fn.mytest = $.mytest = function() {
if ( !! this && this.call && this.apply) {
self = $("a");
} else {
self = this;
}
if(self.is(".stupid")) {
alert("yes, it's stupid");
} else{
alert("no, maybe you are");
}
return this;
};
$.mytest();
$("a").mytest();
小提琴:
http://jsfiddle.net/Abb6a/1/
在Google Chrome浏览器上,一切正常,在IE9中,它表示the object does not supports the property or the method "is"
。
看起来IE9不喜欢我的插件的独立版本,并且在传递参数this
遇到了麻烦。
我该如何解决这个问题?
self
是window
对象的属性,在某些版本的IE中它是只读的。 要解决此问题,只需重命名变量。 或者,如果仅打算在特定的函数范围内使用它,则可以使用var
声明它。
看起来,引用诸如top
, parent
, frames*
, self
, frameElement*
等窗口对象的window
所有属性在IE中都是只读的。 虽然可以在IE> 9中覆盖self
。
*
= frames
是HTMLCollection, frameElement
引用HTML(I)frameElement
,这两个实际上都包含窗口对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.