Javascript $。在IE8中扩展jQuery对象

Javascript $。在IE8中扩展jQuery对象,javascript,jquery,jquery-ui-widget-factory,Javascript,Jquery,Jquery Ui Widget Factory,在小部件工厂中的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对象上使用$.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() {}
});
$.widget(“a07.Wooh”{
选项:{
测试:“棒极了”
},
_testFunc:function(){
//使用this.element jQuery对象在DOM上执行一些操作
this.element.after(“一些很酷的东西”).next().hide();
},
_testFunc2:函数(){
//复制this.element对象
this.element2=$.extend({},this.element);
//使用this.element2 jQuery对象在DOM上执行一些操作
this.element2.next().css('color','red').show();
},
_创建:函数(){
这是._testFunc();
这是._testFunc2();
},
_init:function(){}
});

如上所述,此代码在除IE8之外的所有主要浏览器中都能正常工作。基本上,它为
this.element2.next().css().show()行返回错误消息:

对象不支持此属性或方法

它引用的属性/方法是jQuery方法next()、css()和show()

在IE8中,this.element2似乎丢失了它的jQuery上下文,因为如果我像这样将对象包装在jQuery函数中:
this.element2=$(this.element2)一切都很好


那么问题是,这里发生了什么?这是IE8的标准行为,还是我在编程上错误地处理了这种情况?

如果您的目的只是创建一个包含相同元素的单独jQuery对象,那么这样如何:

this.element2 = $( this.element[0] );

this.element2=$.extend({},this.element)-你的意图是什么?你的小提琴在我的IE8中工作。如果它在你的IE8中工作,你可能已经安装了Chrome框架,或者处于某种三维兼容模式?它在本地测试IE8和BrowserStack.A上的确切行失败,并出现相同的错误。出于我的目的,我只需要this.element对象的备份副本,因为我以后会修改它。或者
this.element2=this.element.clone()
@charlietfl无法工作,因为它创建了元素的副本,但对特定DOM元素的引用丢失。@EasyCo OK。。我仔细看了看小提琴。如果您希望在DOM中引用元素,那么首先制作副本有什么意义