gpt4 book ai didi

javascript - 如何选择不是 'this' 的元素?

转载 作者:数据小太阳 更新时间:2023-10-29 05:50:36 27 4
gpt4 key购买 nike

我有所有具有相同类的 div 列表,我想对所有不是被点击的 div 应用一个函数 (this),我如何选择 !this 使用 jQuery?

更新:我做了这个但它不起作用,知道为什么吗?

    $("li").each(function(){
$("li").not(this).click(function(e) {
$(this).hide();
});
});

更新 2:这是完整的实际代码:

$(".mark").click(function(e) {
e.preventDefault();
var id = "#" + $(this).parent().parent().parent().parent().attr("id") + " ";

var currentStatus = "deleted"; // to be replaced with actual status
var currentStatusClass = "." + currentStatus + "-heading";
$(id + currentStatusClass).show();

$(id + ".edit-headings").click(function(){
$(this).find(".headings-status").show().addClass("bg-hover");

$(id + ".headings-status").click(function() {
$(id + ".headings-status").not(this).hide();
});
});
});

最佳答案

看看 jQuerys not 函数:http://api.jquery.com/not/

$('div').not(this).doSomething();

关于您的更新,请尝试:

        $("li").click(function(e) {
$("li").not(this).hide();
});

关于javascript - 如何选择不是 'this' 的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10383875/

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