循环获取每个TD里的值,但是TD中包含INPUT类型的值无法获取

Tomato514 2011-03-27 03:15:07


function check_form()
{


//alert(jQuery("#tableList").children("tr").length);
// alert( jQuery("#tableList").find("tr").length);


//jQuery("#tableList tr").click(function()
jQuery("tr").each(function () {
var a = new Array();
var i = 0;
jQuery(this).children("td,input").each(function() {
// a[i] = jQuery(this).text();
alert(jQuery(this).text());


// i++;

})

})
}
</script>
</head>
<body>
<table border="1" id="tableList">
<tr>
<td width="50" class="auto">1.0</td>
<td class="auto" width="50"><b>1.1</b></td>
<td class="auto" width="50"><b>1.2</b></td>
<td class="auto" width="50"><b> <input type=text name="Remarks" class="BigInput" value="123"> </b></td>
</tr>
<tr>
<td width="50" class="auto"><b>2.0</b></td>
<td class="auto" width="50"><b>2.1</b></td>
<td class="auto" width="50"><b>2.2</b></td>
<td class="auto" width="50"><b> <input type=text name="Remarks" class="BigInput"> </b></td>
</tr>
<tr >
<td width="50" class="auto"><b>3.0</b></td>
<td class="auto" width="50"><b>3.1</b></td>
<td class="auto" width="50"><b>3.2</b></td>
<td class="auto" width="50"><b> <input type=text name="Remarks" class="BigInput"> </b></td>
</tr>
</table>
<input id="queryBtn" type="button" onclick="check_form();"value="开始查询">
</body>
只能得到alert ( 1.0 1.1 1.2 空 2.0 2.1 2.2 空 3.0 3.1 3.2 空)

这样循环除了IPNUT的值之外都能出来,有啥办法在里面加个选择器把IPNUT的值也给循环出来吗?


...全文
341 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ycproc 2011-03-27
  • 打赏
  • 举报
回复

jQuery('tr td input').each(function(){
alert(jQuery(this).val());
})


循环遍历
camelcanoe 2011-03-27
  • 打赏
  • 举报
回复
如果只是想取循环出Input的值,可以试下:
function check_form(){
jQuery('tr td input').each(function(){
alert(jQuery(this).val());
})
}
lazyboy_wu 2011-03-27
  • 打赏
  • 举报
回复


// 这个代表找的是 子节点的 td,input ,也就是和td同级别的input
// jQuery(this).children("td,input").each(function()

// 这是在当前节点下,找所有包含td,input的节点
jQuery(this).find("td,input").each(function() {
// a[i] = jQuery(this).text();
alert(jQuery(this).text());


// i++;

})

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧