[英]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.