JQuery .prop()单击时选中>假

问题描述 投票:0回答:2

我有一个带有复选框的表单,该表单会生成一个新块,显示由用户选择的滤色器。

Form

在此新块中,我创建了一个click事件,该事件使用“ .buttonRemoveFilter”按钮删除了选定的过滤器。

我尝试取消选中与过滤器结合使用的复选框,但是我只能取消选中所有复选框。

$(document).on("click", ".buttonRemoveFilter", function(){

     $("[id^=branche_search_form_couleurs_").prop("checked", false);
     $(this).parent().parent().remove();
});

[我尝试做的是,当我从新块中删除滤镜时,它将取消选中与此滤镜相关的颜色复选框。

New block

<div class="poPupFiltre">
  <div class="sousBlockPoPup">
    <button class="buttonRemoveFilter">
      <img class="img-fluid imgPoPup" src="{{ asset ('../build/images/supprimer.svg') }}" alt="">
    </button>
    <p class="textPopUp"></p>
  </div>
</div>
jquery click checked prop
2个回答
0
投票

[添加了解您单击哪个过滤器的方法-如果要删除BLANC过滤器,请检查用户是否单击了BLANC过滤器类型。然后使用

访问复选框输入
$("input[value='"+clickedFilterType+"']")

类似这样的东西:

$(document).on("click", ".buttonRemoveFilter", function(){
     let clickedFilterType = $(this).attr("data-type");
     $("input[value='"+clickedFilterType+"']").prop("checked", false);

});

0
投票

尝试这些选项。

在您的表单中,将通用类添加到您的输入复选框(假设类名称为“ .chxbox”)

然后使用此jQuery函数

   $('.chxbox').click(function(){
         id = $(this).attr('id');
         $(id).prop('checked',false);
         $(this).remove();
    });
© www.soinside.com 2019 - 2024. All rights reserved.