2011-02-10 55 views
1

我可以检查是否选中了使用相同类的任何复选框? 如果是,我可以得到所选复选框的ID?有没有办法知道是否使用jquery选择了具有相同类名的任何复选框

<tr> 
<td>Project cost</td> 
<td><input type ="text" id ="pc"/></td> 
<td><input class="change" type="checkbox" name="chkBox" id="chkBox"></input></td> 
<td><input class="sim" type="checkbox" name="chkBox1" id="chkBox1"></input></td> 

</tr> 
<tr> 
<td>Avg hours</td> 
<td><input type ="text" id ="avghrs"/></td> 
<td><input class="change" type="checkbox" name="chkBoxa" id="chkBoxa"></input></td> 
<td><input class="sim" type="checkbox" name="chkBox1a" id="chkBox1a"></input></td> 

</tr> 
<tr> 
<td>Project completion date</td> 
<td><input type ="text" id ="cd"/></td> 
<td><input class="change" type="checkbox" name="chkBoxb" id="chkBoxb"></input></td> 
<td><input class="sim" type="checkbox" name="chkBox1b" id="chkBox1b"></input></td> 

</tr> 

回答

5

您要使用的jQuery :checked selector

$('.change:checked').attr('id'); 

例如

$('.change:checked').each(function() { 
    alert(this.id); 
}); 
0

试试这个:

$(document).ready(function(){ 
    $('input:checkbox').change(function(){ 
     var $class = $(this).attr('class'); 
     $('.'+$class+':checkbox:checked').not(this).each(function(){ 
      alert($(this).attr('id')) 
     }) 
    }) 
}) 
相关问题