gpt4 book ai didi

javascript - Jquery - 包含返回意外结果的方法

转载 作者:行者123 更新时间:2023-12-02 20:29:18 24 4
gpt4 key购买 nike

电子样本在这里:http://jsfiddle.net/SsPqS/

我有一个类为“record”的div,我为每个类为“record”的对象添加了一个点击函数。在点击功能中我有这个:(简化)

$(".record").click(function(e) {
if (!$(e.target).is(':button')) {
if ($.contains($(this).parents(".parentDiv"), $("#UserInformation"))) {
alert("true");
} else {
alert("false");
}
}
});

我不断收到真正的警报,但我不确定为什么,因为 #UserInformation 肯定不在“parrentDiv”类的 div 中

我使用的 contains 函数是否错误?

谢谢!

最佳答案

$.contains()旨在获取 DOM 元素,如下所示:

if ($.contains($(this).closest(".parentDiv")[0], $("#UserInformation")[0])) {

You can test the updated demo here .

关于javascript - Jquery - 包含返回意外结果的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4412125/

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