<script>
function test(){
// some code here .hehe
var objs=document.getElementById("table1").childNodes[0].childNodes
for(var i=0;i<objs.length;i++)
{
if(objs[i].childNodes[0].childNodes[0].checked)
{
objs[i].childNodes[1].childNodes[0].disabled=true;
}
}
}
</script> <BODY onload=test()> <table id="table1">
<tr>
<td><input name=chk type=checkbox value=a checked></td>
<td><input name=txt type=text value=b></td>
</tr>
<tr>
<td><input name=chk type=checkbox value=a ></td>
<td><input name=txt type=text value=b></td>
</tr>
</table>
</BODY>
function test(){
// some code here .hehe
var objs=document.getElementById("table1").childNodes[0].childNodes
for(var i=0;i<objs.length;i++)
{
if(objs[i].childNodes[0].childNodes[0].checked)
{
objs[i].childNodes[1].childNodes[0].disabled=true;
}
}
}
</script> <BODY onload=test()> <table id="table1">
<tr>
<td><input name=chk type=checkbox value=a checked></td>
<td><input name=txt type=text value=b></td>
</tr>
<tr>
<td><input name=chk type=checkbox value=a ></td>
<td><input name=txt type=text value=b></td>
</tr>
</table>
</BODY>
如果table是匿名的,有办法吗?我的代码不希望跟系统有耦合。呵呵
这样代码感觉更糟些,设置个ID做个参数要好些
比如
function test(str){
<body onload=test("table1")>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
function chgDisabledStatus(chk){
var ipts = chk.parentNode.parentNode.cells[1].getElementsByTagName("input");
var status = chk.checked;
for(var i=0,j=ipts.length;i<j;i++)
ipts[i].disabled = status;
}
</script>
</head><body>
<table width="500" border="1" cellspacing="1" cellpadding="1">
<tr>
<td width="40px" align="center">
<input type="checkbox" name="checkbox" id="" onclick="chgDisabledStatus(this)"/></td>
<td width="230px">
<input type="text" name="textfield" id="" />
</td>
<td width="230px"> </td>
</tr>
<tr>
<td align="center"><input type="checkbox" name="checkbox" id="" onclick="chgDisabledStatus(this)"/></td>
<td><input type="text" name="textfield2" id="textfield2" /></td>
<td> </td>
</tr>
<tr>
<td align="center"><input type="checkbox" name="checkbox" id="" / onclick="chgDisabledStatus(this)"></td>
<td><input type="text" name="textfield3" id="textfield3" /></td>
<td> </td>
</tr>
</table>
</body>
</html>