IE9:对象不支持属性“is”

IE9: Object doesn't support the property "is"

本文关键字:is 属性 不支持 对象 IE9      更新时间:2023-09-26

我正在尝试编写一个小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/

谷歌浏览器上一切正常,在IE9中它说the object does not supports the property or the method "is"

看起来IE9不喜欢我的插件的独立版本,并且在传递的参数this有问题。

我该如何解决这个麻烦?

self

window对象的属性,在某些版本的IE中是只读的。要解决此问题,只需重命名变量即可。或者,如果它仅用于特定函数范围,则可以使用 var 声明它。

看起来像引用窗口对象window的所有属性,如topparentframes*selfframeElement*......在 IE 中是只读的。尽管self可以在IE>9中被覆盖。

* = frames 是一个 HTMLCollection,frameElement指的是HTML(I)frameElement,这两个实际上都包含窗口对象。