ウィジェット ファクトリの jQuery オブジェクトで $.extend を使用すると、IE8 は新しく作成されたオブジェクトの jQuery コンテキストを失うようです。実演させてください。
次のコードは IE9+、Chrome、FireFox で動作します
$.widget("a07.Wooh", {
options: {
test: "Awesome"
},
_testFunc: function() {
// Perform some operations on the DOM using this.element jQuery Object
this.element.after("<div class=\"stuff\">Some cool stuff</div>").next().hide();
},
_testFunc2: function() {
//Copy the this.element object
this.element2 = $.extend({}, this.element);
//Perform some operations on the DOM using this.element2 jQuery Object
this.element2.next().css('color', 'red').show();
},
_create: function() {
this._testFunc();
this._testFunc2();
},
_init: function() {}
});
前述のように、このコードはIE8を除くすべての主要なブラウザーで正常に動作します。基本的に、次のthis.element2.next().css().show()
行のエラー メッセージが返されます。
オブジェクトはこのプロパティまたはメソッドをサポートしていません
参照するプロパティ/メソッドは、jQuery メソッドの next()、css()、および show() です。
IE8 では、 this.element2 が jQuery コンテキストを失ったように見えます。オブジェクトを jQuery 関数で次のようにラップすると、this.element2 = $(this.element2);
すべて問題ありません。
問題は、ここで何が起こっているのかということです。これはIE8の標準的な動作ですか、それともプログラムで状況に誤ってアプローチしていますか?