English 中文(简体)
要素内的计票箱
原标题:Count checkboxes within element

I m试图找到一种办法,计算所有经检查的检查箱,,使用 j子的父母。 只要我没有找到一个体面(快速)的解决办法。

说明情况: 我用一个检查箱和每个儿童名单项目一个检查箱填写一份名单。 在没有核对清单项目的情况下,我想不检查所有检查箱。 因此,我假定,每当一个清单变更时,就算出所有核查的清单上项目。

[...]
<li><input type="checkbox" class="checkall" />
<ul>
<li><input type="checkbox" id="ch1" class="list" /></li>
<li><input type="checkbox" id="ch2" class="list" /></li>
<li><input type="checkbox" id="ch3" class="list" /></li>
</ul>
</li>
[...]

As you can see I m working with a nested ul-list, for the record. Sofar I ve got the following jQuery code, which serves for selecting the parent list-item, as I ve only got to count the checkboxes within that group .

// $(this).val() is neccesary for my code to know which checkbox has been affected
var parentnode = $( input#  + $(this).val()).parent().parent().parent();
alert(parentnode.children( input.list:checked ).length);

我知道,它利用儿童选择者( lo、正确吗?)赢得了工作,但我找不到一种办法,可以把经过检查的检查箱长度从母子部分算出。 你们能否帮助我?

最佳回答

由于children()只处理贵元素的直接子女,你可使用find()而不是处理所有与选择人匹配的后代:

alert(parentnode.find( input.list:checked ).length);
问题回答

暂无回答




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签