【问题标题】:new to jquery/javascript i was try to find an inverse to this functionjquery/javascript的新手我试图找到这个函数的逆函数
【发布时间】:2020-04-26 00:54:15
【问题描述】:

我原来的脚本是这样的

<script type="text/javascript">
jQuery(document).ready(function(){
$("#rad1 :checkbox").click(function() {
       $("div.abc1").hide();
       $("#rad1 :checkbox:checked").each(function() {
           $("." + $(this).val()).show();
       });
    });
});
</script>

感谢用户 nnnnnn here 的回答

正如我在标题中所说,我希望反转操作 IE。显示所有内容,然后隐藏所有未选择的元素

搜索后我找到了 :not() 选择器,但我无法实现它

jQuery(document).ready(function() {
    $("#rad1 :checkbox").click(function() {

        $("div.abc1").show();
        $("#rad1 :checkbox:checked").each(function()  {
            $("." + (:not($(this))).val()).hide();
        });
    });
});

任何帮助将不胜感激。

【问题讨论】:

  • $(":not(" + $(this) + ")")? :not 是一个选择器,不是有效的 JS

标签: javascript jquery html


【解决方案1】:

您将:not 放在错误的位置,它是选择器查询的一部分,而不是 JS 代码

jQuery(document).ready(function() {
    $("#rad1 :checkbox").click(function() {

        $("div.abc1").show();
        $("#rad1 :checkbox:not(:checked)").each(function()  {
            $("." + $(this).val()).hide();
        });
    });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-04
    • 1970-01-01
    • 1970-01-01
    • 2022-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多