日期:2014-05-16  浏览次数:20385 次

checkbox控制text的disable,这个可能有点难
因为每行(tr)都是从数据库中提取的,有没有什么好办法,能使用第一个td内的checkbox控制第二个td里的text的disabled状态。这样的dom的操作,哥们还没到那境界,呵呵。~~~~~~~~~~~~~   谢先了。

下面是我写的片断,大侠可以凑合用。

              <script>    
function   test(){
//   some   code   here   .hehe
}
</script>

<BODY   onload=test()>      

<table>
<tr>
<td> <input       name=chk     type=checkbox       value=a> </td>
<td> <input       name=txt       type=text       value=b> </td>
</tr>
</table>
   
</BODY>

------解决方案--------------------
<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>
------解决方案--------------------
var objs=document.getElementsByTagName( "table ")[0].childNodes[0].childNodes

所有的table都是数组形式

------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<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 "> &nbsp; </td>
</tr>
<tr>
<td align= "center "> <input type= "checkbox " name= "checkbox " id= " " onclick= "chgDisabledStatus(this) "/> </td>