首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

checkbox控制text的disable,这个可能有点难,该如何解决

2012-02-08 
checkbox控制text的disable,这个可能有点难因为每行(tr)都是从数据库中提取的,有没有什么好办法,能使用第

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>


<td> <input type= "text " name= "textfield2 " id= "textfield2 " /> </td>
<td> &nbsp; </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> &nbsp; </td>
</tr>
</table>
</body>
</html>

热点排行