gpt4 book ai didi

javascript - 如何通过单击子 ID 找到父 ID,然后通过 jquery 获取父 ID 来查找子 ID

转载 作者:行者123 更新时间:2023-11-28 05:44:18 30 4
gpt4 key购买 nike

我正在产品页面上创建评论模块,其中显示垃圾评论选项,并显示 onclick 显示和隐藏弹出窗口。现在它在单个评论中工作正常但是当评论是两个时它同时打开两个因为类是相同的。现在这就是为什么我想要获取父 li id,这样我们只能找到该 id 而不是另一个的内部类

这是我的 jsfiddle链接

这是我的脚本

$(".slidermenudown .fa-angle-down").on("click",function(){

if($(".anthr_usr_cmnt").hasClass("active")){

$(".anthr_usr_cmnt").removeClass("active");

}else{
if($(".owner_cmnt").hasClass("active")){
$(".owner_cmnt").removeClass("active");
}
$(".anthr_usr_cmnt").addClass("active");
}

});

最佳答案

试试这个,我已经修改了你的 fiddle 本身和你的 css。

https://jsfiddle.net/Lse3s3uv/3/

.active{
display:block;
}

    $(".slidermenudown .fa-angle-down").on("click", function() {

var $this = $(this).parents('.comment'); // "this" is the click's target.
console.log($this);
var $anthr = $this.find(".anthr_usr_cmnt");
console.log($anthr);
var $owner = $this.find(".owner_cmnt");
console.log($owner);

if ($anthr.hasClass("active")) {
$anthr.removeClass("active");
} else {
if ($owner.hasClass("active")) {
$owner.removeClass("active");
}
//to remove hide others
$('.anthr_usr_cmnt').removeClass('active');

$anthr.addClass("active");
}
});

关于javascript - 如何通过单击子 ID 找到父 ID,然后通过 jquery 获取父 ID 来查找子 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37696574/

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