小编Dre*_*ild的帖子

淘汰赛及其绑定

我有两个复选框,我希望这些复选框的值相互依赖.当我检查第一个复选框时,第二个是取消选中,当我取消选中第一个时,第二个被检查,反之亦然.我可以用jQuery做这个:例子.

$('input').on('change', 
     function() {         
         var anotherId = $(this).attr('id') == 'first' ? 'second' : 'first';        
         if($(this).is(':checked'))
             $('[id="' + anotherId + '"]').removeAttr('checked');
         else 
             $('[id="' + anotherId + '"]').attr('checked', 'true');
     });
Run Code Online (Sandbox Code Playgroud)

但这不是我想的最好的方式.我知道我可以用knockout.js来做,但不知道怎么做.你能帮我解决这个问题吗?

html binding knockout.js

0
推荐指数
1
解决办法
42
查看次数

标签 统计

binding ×1

html ×1

knockout.js ×1