javascript/jquery统计当前行中的复选框数
我有以下表格行:javascript/jquery统计当前行中的复选框数,javascript,jquery,checkbox,count,checked,Javascript,Jquery,Checkbox,Count,Checked,我有以下表格行: <table class="authors-list"> <tr> <td style="font-size:10px;"><a class="deleteRow"> <img src="delete2.png" /></a></td> <td ><input type="text" id="product1" name="pro
<table class="authors-list">
<tr>
<td style="font-size:10px;"><a class="deleteRow"> <img src="delete2.png" /></a></td>
<td ><input type="text" id="product1" name="product1" class="rounded"/></td>
<td ><input type="text" size='5' id="qty1" name="qty1" class="rounded"/></td>
<td class="tdcheckbox"><input type="checkbox" id="h09_1" name="h09_1" class="rounded"/></td>
<td class="tdcheckbox"><input type="checkbox" id="h12_1" name="h12_1" class="rounded"/></td>
<td class="tdcheckbox"><input type="checkbox" id="h15_1" name="h15_1" class="rounded"/></td>
<td class="tdcheckbox"><input type="checkbox" id="h18_1" name="h18_1" class="rounded"/></td>
<td class="tdcheckbox"><input type="checkbox" id="h21_1" name="h21_1" class="rounded"/></td>
<td class="tdcheckbox"><input type="checkbox" id="h24_1" name="h24_1" class="rounded"/></td>
<td class="tdcheckbox"><input type="checkbox" id="h27_1" name="h27_1" class="rounded"/></td>
<td class="tdcheckbox"><input type="checkbox" id="h30_1" name="h30_1" class="rounded"/></td>
<td><input type="hidden" name="checkedsizes_1" id="checkedsizes_1" value="0"></td>
</tr>
</table>
调用的函数是:
<SCRIPT>
function submitFunction() {
document.sales_order_details.action="/sales/new_autospread_range";
</SCRIPT>
函数submitFunction(){
document.sales\u order\u details.action=“/sales/new\u autospread\u range”;
因此,我设想如下:
<SCRIPT>
function submitFunction() {
countcheckboxperrow();
document.sales_order_details.action="/sales/new_autospread_range";
</SCRIPT>
<script>
countcheckboxperrow(){;
var checkboxes=0;
//foreach table row in table class="authors-list" count the checkedcheckboxes starting with h. [id^="h"] h being field name first letter
//set the corresponsing input in that field row that starts with
//repeat for next row id^="checkedsizes"]
</script>
函数submitFunction(){
countcheckboxperrow();
document.sales\u order\u details.action=“/sales/new\u autospread\u range”;
countcheckboxperrow(){;
var复选框=0;
//对于table class=“authors list”中的每个表行,计算以h开头的复选框。[id^=“h”]h是字段名的第一个字母
//在以开头的字段行中设置相应的输入
//对下一行id^=“checkedsizes”重复此操作
提前感谢您的帮助,并让我知道是否需要澄清。总之,我需要一个脚本来计算该行中复选框的数量,并用此值填充隐藏的ffield
再次感谢
小提琴
我还没有测试过,但类似jQuery的东西应该可以做到这一点
countChecks(){
$('.author-list tr').each(function(){
var count = 0;
var hdn = $(this).find('input[name^="checkedsizes"]');
count = $(this).find(':checkbox:checked').length;
hdn.val(count);
});
}
谢谢Mark,你能复习一下我的小提琴吗?我只是被卡住了,在这里连基本的东西都学不到:-)再次谢谢。@Smudger看起来你有一些语法问题等等,它对我仍然不起作用,但我的机器上的JSFIDLE有问题-看看这里-谢谢Mark。太棒了,谢谢你的帮助。全部排序::-)
countChecks(){
$('.author-list tr').each(function(){
var count = 0;
var hdn = $(this).find('input[name^="checkedsizes"]');
count = $(this).find(':checkbox:checked').length;
hdn.val(count);
});
}