jquery中的第一个子级

jquery中的第一个子级,jquery,Jquery,HTML: 自定义JQUERY方法 var element = $(".wrapper"); element.toggle().children(":first").custom(); $(".wrapper .panel").custom(); 奇怪的是,当我在IE中执行console.log时,它显示了对panel元素的第一次调用作为 [对象HTMLGenericElement] 但第二个调用将其显示为[ObjectHtmlLevel] 为什么会这样以及如何使第一个调用成为[ObjectH

HTML:

自定义JQUERY方法

var element = $(".wrapper");
element.toggle().children(":first").custom();
$(".wrapper .panel").custom();
奇怪的是,当我在IE中执行console.log时,它显示了对panel元素的第一次调用作为

[对象HTMLGenericElement]

但第二个调用将其显示为[ObjectHtmlLevel]

为什么会这样以及如何使第一个调用成为[ObjectHtmlLevel]

您应该在
每个
函数中使用
$(this)
而不是
this

  $.fn.custom = function() {  
        return this.each(function() {
           console.log(" this = ", this);
               // do something to each dom element.
        });
    };
此外,我使用chrome、safari、firefox和所有我收到
元素的地方进行了检查。根据这一点,它们都被记录为[object HtmlLevel]


在IE9(版本9.0.8112.16421 64位)中进行测试。

仍然会返回相同的版本results@SKS,你为什么不看看page@Starx这与你的回答相矛盾。无论如何,OP说结果是一样的。
  $.fn.custom = function() {  
        return this.each(function() {
           console.log(" this = ", this);
               // do something to each dom element.
        });
    };
return this.each(function() {
    console.log(" this = ", $(this));
    // do something to each dom element.
})