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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM