jQuery對象相等如何確定兩個jQuery對象是否相等?我希望能夠為特定的jQuery對象搜索數組。$.inArray(jqobj, my_array);//-1
alert($("#deviceTypeRoot") == $("#deviceTypeRoot"));//False
alert($("#deviceTypeRoot") === $("#deviceTypeRoot"));//False
3 回答

qq_笑_17
TA貢獻1818條經驗 獲得超7個贊
.is
var a = $('#foo');var b = a;if (a.is(b)) { // the same object!}
var a = $('#foo');var b = a;
if ($.data(a) == $.data(b)) { // the same object!}
a === b
$.fn.equals = function(compareTo) { if (!compareTo || this.length != compareTo.length) { return false; } for (var i = 0; i < this.length; ++i) { if (this[i] !== compareTo[i]) { return false; } } return true;};
var a = $('p');var b = $('p');if (a.equals(b)) { // same set}

catspeake
TA貢獻1111條經驗 獲得超0個贊
alert($("#deviceTypeRoot")[0] == $("#deviceTypeRoot")[0]); //Truealert($("#deviceTypeRoot")[0] === $("#deviceTypeRoot")[0]);//True
$("#deviceTypeRoot")

侃侃爾雅
TA貢獻1801條經驗 獲得超16個贊
$.fn.equals(...)
JSON.stringify(a) == JSON.stringify(b)
- 3 回答
- 0 關注
- 586 瀏覽
相關問題推薦
添加回答
舉報
0/150
提交
取消