同一元素的jQuery对象不相等?

前端之家收集整理的这篇文章主要介绍了同一元素的jQuery对象不相等?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这一定是我忽略的东西,但是请看下面的页面JavaScript并告诉我为什么,对于所有神圣的东西,jQuery不会返回true?

HTML:http://alcatel.scottbuckingham.com/reporting/test.html

<p class="test">hello1</p>

JS:http://alcatel.scottbuckingham.com/reporting/_scripts/collapse.js

;(function($,window,document,undefined) {

        var t = $('.test');
        var s = $('.test');

        console.log(t);
        console.log(s);

        if (t === s) {
            console.log('yes');
        }

})(jQuery,document);

我真的花了几个小时试图解决这个问题并将其减少到几乎1 === 1statement,这是行不通的.

任何帮助都非常感谢!

解决方法

试试这个 – 工作演示 – > http://jsfiddle.net/mohammadAdil/tHjgN/
if(t.is(s)) {
    console.log('yes');
 }

http://api.jquery.com/is/

或者===

if (t.get(0) === s.get(0)) { //<--Compare DOM elements instead of jquery object's
    console.log('again yes');
}

演示 – > http://jsfiddle.net/mohammadAdil/tHjgN/1/

原文链接:https://www.f2er.com/jquery/178617.html

猜你在找的jQuery相关文章