2015-05-29 141 views
0

enter image description here選擇所有複選框,當只有一個點擊

如何選擇單點擊所有複選框,而每一個複選框已使用JavaScript唯一的名稱?請提供代碼。

</div><!-- /.box-header --> 
<div class="box-body"> 
<form name="permissionfrm" method="post" id="permissionfrm"> 
<input type="hidden" name="permission" id="permission" value="assignpermission" /> 
    <table id="example1" class="table table-bordered table-striped"> 
    <thead> 
    <tr> 
     <th>Give All Permissions 
     </th><td><input type="checkbox" name="addadmin" id="addadmin" value="Check All" onClick="this.value=check(this.form.list)"/></td> 
     </tr> 
     <tr> 
     <th>Add</th> 
     <th>Edit</th> 
     <th>View</th> 
     <th>Delete</th> 
     </tr> 
    </thead> 
    <tbody> 
+0

Java與JavaScript無關! – Dragondraikk

回答

0

利用一個普通的類。添加common class所有輸入checkbox

<input type="checkbox" class="check"... 
         ^^^^^^^^^^^^ 

在jQuery的按鈕點擊:

$('.check').prop('checked', true); 
0

使用將指定的類名相同的那些你想要檢查誰做一下,經過的好辦法特定元素。

<input type="checkbox" class="class_name" > 

而現在jquery將爲你做的工作。 元素的單擊事件後做出的複選框選中

$(".class_name").click(function(){ 
    $('#myCheckbox').attr('checked', true); 
}); 

這裏ID mycheckbox是你想選中複選框,所有複選框的id's

希望這可以幫助你!

相關問題