开发者

Is there a way know if any checkboxes with same class name is selected using jquery

Can i check if any checkbox using the same class is selected? If yes can i get the id of the selected checkbox?

<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开发者_JAVA百科>
<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>


You want to use the jQuery :checked selector

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

for example

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


Try this :

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜