【问题标题】:Select all check boxes and show control buttons in bootstrap选中所有复选框并在引导程序中显示控制按钮
【发布时间】:2023-03-16 23:24:02
【问题描述】:

选中任何复选框后,我已经能够显示/隐藏 div。我还能够创建一个选中所有复选框的检查所有按钮。现在的问题是如何将两者联系在一起?

当我点击全部检查时,它不会显示/隐藏我想要显示/隐藏的 div,但是当您单独选择每个 div 时它会起作用。 Here is the page url

奖励:如果有人也能做到,那么“全选”按钮变为“取消全选”谢谢社区!

脚本:

<script>
$('input[type=checkbox]').change(
function(){
   if($('input[type=checkbox]').is(':checked')){
          // if any of the checkboxes are checked then make the area visible
          $('.send-control').fadeIn(); 
   }else{
          // only if all are unchecked will this fire and hide the area
          $('.send-control').fadeOut();
   }
});

$('#toggle-all').click(function() {
$('input[type="checkbox"]').prop('checked',true);
});
</script>

【问题讨论】:

    标签: twitter-bootstrap checkbox


    【解决方案1】:

    尝试将 .change() 添加到您的方法中:

     $('input[type="checkbox"]').prop('checked',true).change();
    

    据我所知,您必须手动调用更改方法,否则更改事件将不会被注册。

    【讨论】:

    • 就是这样。谢谢,现在我可以专注于将全选按钮更改为取消选择。
    猜你喜欢
    • 2015-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-06
    • 2013-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多