2015-05-29 96 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

希望这可以帮助你!

相关问题