[英]IE9: Object doesn't support the property “is”
I'm trying to write a little jQuery plugin but I've problems with (of course) Internet Explorer 9. 我正在尝试编写一个小jQuery插件,但是(当然)Internet Explorer 9出现了问题。
This is the code: 这是代码:
$.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();
Fiddle: 小提琴:
http://jsfiddle.net/Abb6a/1/ http://jsfiddle.net/Abb6a/1/
On Google Chrome everything works fine, in IE9 it says that the object does not supports the property or the method "is"
. 在Google Chrome浏览器上,一切正常,在IE9中,它表示
the object does not supports the property or the method "is"
。
Looks like IE9 doesn't like the standalone version of my plugin and has troubles with the passed argument this
. 看起来IE9不喜欢我的插件的独立版本,并且在传递参数
this
遇到了麻烦。
How can I solve this trouble? 我该如何解决这个问题?
self
is a property of window
object, and it's read-only in some versions of IE. self
是window
对象的属性,在某些版本的IE中它是只读的。 To fix the problem, just rename your variable. 要解决此问题,只需重命名变量。 Or if it's purposed to be used in a particular function scope only, you can declare it with
var
. 或者,如果仅打算在特定的函数范围内使用它,则可以使用
var
声明它。
Looks like all properties of window
referring a window object like top
, parent
, frames*
, self
, frameElement*
... are read-only in IE. 看起来,引用诸如
top
, parent
, frames*
, self
, frameElement*
等窗口对象的window
所有属性在IE中都是只读的。 Though self
can be overridden in IE>9. 虽然可以在IE> 9中覆盖
self
。
*
= frames
is a HTMLCollection, frameElement
refers to HTML(I)frameElement
, both of these actually contain window object(s). *
= frames
是HTMLCollection, frameElement
引用HTML(I)frameElement
,这两个实际上都包含窗口对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.