简体   繁体   中英

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.

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/

On Google Chrome everything works fine, in IE9 it says that 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 .

How can I solve this trouble?

self is a property of window object, and it's read-only in some versions of 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 .

Looks like all properties of window referring a window object like top , parent , frames* , self , frameElement* ... are read-only in IE. Though self can be overridden in IE>9.

* = frames is a HTMLCollection, frameElement refers to HTML(I)frameElement , both of these actually contain window object(s).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM