cuốn sách gpt4 ai đã làm

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

In lại Tác giả: Walker 123 更新时间:2023-11-28 05:44:18 31 4
mua khóa gpt4 Nike

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

đây là của tôi jsfiddleliên kết

这是我的脚本

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

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

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

}khác{
if($(".owner_cmnt").hasClass("active")){
$(".owner_cmnt").removeClass("active");
}
$(".anthr_usr_cmnt").addClass("active");
}

});

câu trả lời hay nhất

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

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

.active{
hiển thị:khối;
}

    $(".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");
} khác {
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/

31 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress