【JS】限制兩個或多個單選框最多只能選擇一個


 1  $(function () {
 2             /*$("#checkbox1").click(function(){
 3                 if($(this).attr("checked") == true){
 4                     $("#checkbox2").attr("checked",false);
 5                 }
 6             });
 7             $("#checkbox2").click(function(){
 8                 if($(this).attr("checked") == true){
 9                     $("#checkbox1").attr("checked",false);
10                 }
11             });*/
12             var allBox = $(":checkbox");
13             allBox.click(function () {
14                if(this.checked){
15                    allBox.removeAttr("checked");
16                    $(this).attr("checked", "checked");
17                  }
18             });
19         });
1 <td><input value="1" type="checkbox" id="checkbox1"/>在售<input value="2" type="checkbox" id="checkbox2"/>售罄</td>

 


免責聲明!

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



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