dongqindu8110 2015-02-03 19:25
浏览 34
已采纳

如何在检查数组中的另一个时使用jquery取消选中复选框

Hi guys I have a "datatable" with the following checkboxes on it:

<input type="checkbox" name="total_balance[]"  id="total_balance" class="total_balance" value="<?= $balance['supplierID'] ?>" />

<input type="checkbox" name="no_payment[]"  id="no_payment" class="no_payment" value="<?= $balance['supplierID'] ?>" />

That is a loop, so I've hundred of the same names but with different values by row. So what I want is when I check the total_balance[] that has the value=1, for example, it's uncheck, if is checked, the no_payment[] with value=1, and so on.. like if I click the total_balance[] with value=32, uncheck the no_payment with value=32...

How to I do that in jquery??

I've tried like that:

$('input[name="total_balance"]').change(function() {
        console.log(this.value);
        var val = this.value;
        $('input:no_payment[value="' + val + '"]').attr('checked', false);
     });


      $('input[name="no_payment"]').change(function() {
        console.log(this.value);
        var val = this.value;
        $('input:total_balance[value="' + val + '"]').attr('checked', false);
     });

but doesn't work

tks!

  • 写回答

1条回答 默认 最新

  • douyangquan2474 2015-02-03 19:44
    关注

    got it:

    $('.total_balance').click(function() {
            var val = this.value;
            $('.no_payment[value="' + val + '"]').attr('checked', false);
         });
    
    
          $('.no_payment').click(function() {
            var val = this.value;
            $('.total_balance[value="' + val + '"]').attr('checked', false);
         })
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿