在线急等表格中同一行的文本框和CHECKBOX之间关系处理问题!!!!

asplhk 2005-08-06 12:22:15
<table id=qqq>
<tr>
<td><input type=text name=q value=1></td><td><input type=checkbox></td>
</tr>
</table>
表格为动态生成的多行表格
如何在程序中遍历表格,并判断文本框不为空且大于零的情况下,同一行的复选框忘记选中问题
...全文
132 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
cxz7531 2005-08-06
  • 打赏
  • 举报
回复
<script>
function init(){
var allrow=qqq.childNodes(0);
for(var i=0;i<allrow.childNodes.length;i++){
var s=allrow.childNodes.item(i);
var ins=s.getElementsByTagName("INPUT");
var svalue=ins.item(0).value;
ins.item(1).checked=((svalue!=null) && (svalue!='') && (Number(svalue)>0));
}
}
</script>
<body onload="init();">
<table id=qqq>
<tr><td><input type=text name=q value=""></td><td><input type=checkbox></td></tr>
<tr><td><input type=text name=q value="0"></td><td><input type=checkbox></td></tr>
<tr><td><input type=text name=q value=1></td><td><input type=checkbox></td></tr>
<tr><td><input type=text name=q value=2></td><td><input type=checkbox></td></tr>
</table>
</body>
duwan 2005-08-06
  • 打赏
  • 举报
回复
<!-- 看看这个可以吗? 有一种情况我没考虑就是选中,而输入框为空时,你好像也没要求
-->
<table id=qqq>
<tr>
<td><input type=text name=q value=132 ></td><td><input type=checkbox checked></td>
</tr>
<tr>
<td><input type=text name=q value=0></td><td><input type=checkbox></td>
</tr>
<tr>
<td><input type=text name=q value=1></td><td><input type=checkbox></td>
</tr>
<tr>
<td><input type=text name=q value=1></td><td><input type=checkbox checked></td>
</tr>
<tr>
<td><input type=text name=q value=></td><td><input type=checkbox checked></td>
</tr>
</table>
<input type=button name=q value=check onClick="check();">
<script>
<!--
function check()
{
o=document.getElementById("qqq")
for(i=0;i<o.rows.length;i++)
{

if(o.rows[i].cells[0].children[0].value!="")
if(o.rows[i].cells[0].children[0].value>0)
if(!o.rows[i].cells[1].children[0].checked)
alert("no checked at row:"+(i+1))
}
}
-->
</script>

87,922

社区成员

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

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