gpt4 book ai didi

javascript - jQuery - DOM 元素未被识别为相等

转载 作者:行者123 更新时间:2023-11-28 13:51:54 24 4
gpt4 key购买 nike

Possible Duplicate:
How would you compare jQuery objects?

我正在使用 jQuery 将主动单击的项目存储在项目列表中。我想检测新单击的项目是否与之前单击的项目相同,以切换支持 div 的可见性。我的代码如下所示:

var curPin;

$('.pin').click(function(){
var $pin = $(this);
if (curPin == $pin){
console.log('true');
} else {
curPin = $pin;
console.log('false');
}
}

为什么这不相等?有更好的方法吗?

最佳答案

使用if ($(this).is(curPin))检查元素是否相同。

关于javascript - jQuery - DOM 元素未被识别为相等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10283106/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com