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 关注
- 609 浏览
相关问题推荐
添加回答
举报
0/150
提交
取消
