admin管理员组文章数量:1208155
I want to check if the first checkbox in a tr is selected not all the checkbox that is found in this tr.
For the time being i have this code :
var b = false;
$j('#tb1 td input:checkbox').each(function(){
if($j(this).is(':checked')){
b = true;
}
});
this check if there is at least one checkbox check but if i add this to my selector :
$j('#tb1 td input:first:checkbox').each(function(){
if($j(this).is(':checked')){
b = true;
}
});
it check for only the first row not for all the rows and only the first checkbox. How can i achieve this by using the "first" selector ? Thanks in advance
I want to check if the first checkbox in a tr is selected not all the checkbox that is found in this tr.
For the time being i have this code :
var b = false;
$j('#tb1 td input:checkbox').each(function(){
if($j(this).is(':checked')){
b = true;
}
});
this check if there is at least one checkbox check but if i add this to my selector :
$j('#tb1 td input:first:checkbox').each(function(){
if($j(this).is(':checked')){
b = true;
}
});
it check for only the first row not for all the rows and only the first checkbox. How can i achieve this by using the "first" selector ? Thanks in advance
Share Improve this question edited Sep 19, 2013 at 6:37 Harry 89.8k26 gold badges212 silver badges222 bronze badges asked Sep 19, 2013 at 6:36 vanessenvanessen 1,2601 gold badge14 silver badges19 bronze badges 2- can u create jsfiddle... – Somnath Kharat Commented Sep 19, 2013 at 6:40
- do you want to validate whether all the first checkboxes are checked or whether any one of them is checked – Arun P Johny Commented Sep 19, 2013 at 6:41
4 Answers
Reset to default 14Try
var b = false;
$j('#tb1 tr').find('input:checkbox:first').each(function(){
if(this.checked){
b = true;
}
});
Your jquery
code is wrong, you are using the correct selector
but in wrong place..try this
$j('#tb1 td input:checkbox:first').
More infor about :First
is here
Please try it
var b = false;
$j('#tb1 tr input:checkbox:first').each(function(){
if(this.checked){
b = true;
}
});
You are doing correct but placing of selector is wrong.
change
$j('#tb1 td input:first:checkbox').
to
$j('#tb1 td input:checkbox:first').
本文标签: javascriptjquery get only first checkbox of a trStack Overflow
版权声明:本文标题:javascript - jquery get only first checkbox of a tr - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738734078a2109493.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论