[英]How to iterate over a table cells using jQuery?
我是jQuery的新手,正在尝试学习它。 我想遍历一个9 * 9
网格,以警告input
框的值(总计81),逐行,逐列和逐格3 * 3
。
这是我尝试过的:
$("#checkBox").change(function () {
if (this.checked) {
$('table tr').each(function () {
alert($(this).td.input.val());
});
$('table tr').each(function () {
alert($(this).td.input.val());
});
} else {
alert("Check Box is unchecked. AutoCheck is disabled.");
}
});
只有else alert
起作用。 任何意见或指导表示赞赏。
代码的$(this).td.input.val()
这部分将引发错误,因为jquery对象不包含名为td
的属性。
尝试,
//The following snippet would alert the text inside of each td
$('table tr td').each(function () {
alert($(this).text());
});
//The following snippet would alert the value of each input each td
$('table tr td input').each(function () {
alert($(this).val());
});
如果您想逐行迭代,请尝试,
$('table tr').each(function () {
$(this).find('td').each(function(){
$(this).find(':input').each(function(){
alert($(this).val());
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.