这一定是我忽略的东西,但是请看下面的页面和JavaScript并告诉我为什么,对于所有圣洁的东西,jQuery不会返回true?
HTML:http://alcatel.scottbuckingham.com/reporting/test.html
<p class="test">hello1</p>
Run Code Online (Sandbox Code Playgroud)
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, window, document);
Run Code Online (Sandbox Code Playgroud)
我花了好几个小时试图解决这个问题并将其减少到这个,几乎是1 === 1不起作用的声明.
任何帮助都非常感谢!
试试这个 - 工作演示 - > http://jsfiddle.net/mohammadAdil/tHjgN/
if(t.is(s)) {
console.log('yes');
}
Run Code Online (Sandbox Code Playgroud)
或者 ===
if (t.get(0) === s.get(0)) { //<--Compare DOM elements instead of jquery object's
console.log('again yes');
}
Run Code Online (Sandbox Code Playgroud)
演示 - > http://jsfiddle.net/mohammadAdil/tHjgN/1/
| 归档时间: |
|
| 查看次数: |
5755 次 |
| 最近记录: |