jquery计算一行中的复选框数
我的表a如下所示:jquery计算一行中的复选框数,jquery,count,checkbox,Jquery,Count,Checkbox,我的表a如下所示: <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="pr
<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>
这目前不起作用。感谢您对答案或小提琴的任何帮助。我使用的是jQuery1.9.1
请记住,我的表有多行,因此需要循环遍历每一行
再次感谢。声明某个东西是函数并正确引用它会有所帮助 必须声明
countChecks(){
函数countChecks(){
而countchecks();
应该是countchecks();
当您为表指定class。authors list
时,使用正确的类名选择它也很有用
$('.authors list tr')…
应为$('.authors list tr')…
其他一切都很好。声明某个东西是函数并正确引用它会有所帮助 必须声明
countChecks(){
函数countChecks(){
而countchecks();
应该是countchecks();
当您为表指定class。authors list
时,使用正确的类名选择它也很有用
$('.authors list tr')…
应为$('.authors list tr')…
其他一切都很好。您有一些打字错误/语法错误,我已对其进行了修改:
function submitFunction(){
alert("call countchecks");
countChecks();
alert("checkedsizes populated");
alert("continue with submit");
}
function countChecks(){
$('.authors-list tr').each(function(){
var count = 0;
var hdn = $(this).find('input[name^="checkedsizes"]');
count = $(this).find(':checkbox:checked').length;
hdn.val(count);
alert(count);
});
}
你会发现你的主要错误是
uncaughtreferenceerror:submitFunction没有定义,因为你在内联调用你的函数,所以这个函数必须是全局定义的,这意味着你不能在加载时加载脚本。这可以在jsFiddle中完成,我已经修改了你的,创建了一个工作版本: 您有一些拼写错误/语法错误,我已对其进行了修改:
function submitFunction(){
alert("call countchecks");
countChecks();
alert("checkedsizes populated");
alert("continue with submit");
}
function countChecks(){
$('.authors-list tr').each(function(){
var count = 0;
var hdn = $(this).find('input[name^="checkedsizes"]');
count = $(this).find(':checkbox:checked').length;
hdn.val(count);
alert(count);
});
}
你会发现你的主要错误是uncaughtreferenceerror:submitFunction没有定义,因为你在内联调用你的函数,所以这个函数必须是全局定义的,这意味着你不能在加载时加载脚本。这可以在jsFiddle中完成,我已经修改了你的,创建了一个工作版本: 您的JS中有很多输入错误。下面的代码可以正常工作,除了从按钮中删除事件侦听器并将其放在JS中它所属的位置外,不会更改任何标记:
$(function () {
var countChecks = function () {
$('.authors-list tr').each(function(){
var count,
hdn = $(this).find('input[name^="checkedsizes"]');
count = $(this).find('input:checked').length;
hdn.val(count);
});
}
$('input[type="button"]').click(function () {
alert("call countchecks");
countChecks();
alert("checkedsizes populated");
alert("continue with submit");
});
});
我已经相应地更新了你的提琴。你的JS中有很多打字错误。下面的代码可以正常工作,除了从按钮中删除事件侦听器并将其放入JS中之外,不会更改任何标记:
$(function () {
var countChecks = function () {
$('.authors-list tr').each(function(){
var count,
hdn = $(this).find('input[name^="checkedsizes"]');
count = $(this).find('input:checked').length;
hdn.val(count);
});
}
$('input[type="button"]').click(function () {
alert("call countchecks");
countChecks();
alert("checkedsizes populated");
alert("continue with submit");
});
});
我已相应地更新了您的小提琴。以下是正确的JS代码:
function submitFunction (){
alert("call countchecks");
countChecks();
alert("checkedsizes populated");
alert("continue with submit");
}
function 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);
});
}
除了输入错误,您还需要更改左侧的框架和扩展设置,默认设置为“onDomready”,您需要将其更改为“no wrap-in”。下面是正确的JS代码:
function submitFunction (){
alert("call countchecks");
countChecks();
alert("checkedsizes populated");
alert("continue with submit");
}
function 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);
});
}
除了输入错误,您还需要更改左侧的框架和扩展设置,默认设置为“onDomready”,您需要将其更改为“no wrap-in”。选择器将为“input[type='checkbox']:checked”。$(this).find(“input[type='checkbox']:checked”).length将为您计数谢谢Dimitri,您能帮我拉小提琴吗?非常感谢。:checkbox:checked
很好。这是打字错误、打字错误和更多的打字错误。选择器将是“input[type='checkbox']:checked”。$(this)。find(“input[type='checkbox']:checked”).length会给你计数谢谢Dimitri,你能帮我拉小提琴吗?非常感谢。:复选框:选中
就可以了。这是打字错误、打字错误和更多的打字错误。这不仅仅是打字错误,内联函数调用要求在正确的范围内声明函数(全局)我删除了onclick并替换为jQueryTanks Popleak。感谢。这不仅仅是打字错误,内联函数调用要求在正确的作用域(全局)中声明函数我删除了onclick并替换为jQueryTanks PopLaines。谢谢。什么是no wrap-in
do?谢谢。内联函数调用要求在正确的范围内声明函数(全局),“no wrap-in head”将在“global”作用域中声明这两个函数,而不是在“ondomcumentrady”作用域中声明这两个函数。您在“onDomready”作用域中声明了这两个函数,只能在内部调用,不能在onclick event外部调用。谢谢。no wrap-in
do做什么?谢谢。内联函数调用要求在c中声明这些函数正确范围(全球),“no wrap-in head”将在“global”范围内声明这两个函数,而不是“OnDomcumentrady”。您在“onDomready”范围内声明了这两个函数,您只能在内部调用它们。而不能在onclick事件外部调用它们。谢谢Billy,非常感谢您的输入。很高兴成为输入:)谢谢Billy,非常感谢您的输入。恳请原谅确保是输入:)