JS动态添加checkbox实现多选框只能选一个

 1 function addCheckBox(){//JS生成的checkbox
 2     var html='';
 3     html+='<input type="checkkbox" />';
 4     html+='<input type="checkkbox" />';
 5     html+='<input type="checkkbox" />';
 6     $('#log_window').html(html);
 7 }  
 8 
 9 function checkedOnlyOne() {
10         //if ($(this).is(":checked")) {
11         //    $("#log_window input[type='checkbox']").attr("checked", false);
12         //    $(this).attr("checked", true);
13         //} //一般情况下用这个就可以
14         $(document).ready(function(){  //JS生成的checkbox要加上这句
15             $('#log_window').find('input[type=checkbox]').bind('click', function () {
16                 $('#log_window').find('input[type=checkbox]').not(this).attr("checked", false);
17             });
18         });
19     }
20 //html
21 <div id="log_window"></div>

 

posted @ 2017-10-13 11:23  又是我  阅读(8265)  评论(0)    收藏  举报