使用复选框控制表格中的文本框

来源:互联网 发布:网络cn是什么意思啊 编辑:程序博客网 时间:2024/06/05 18:30

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />

<title>使用复选框控制表格中的文本框</title>

<script language="javascript">

function chkOper(chk)

{

    var inputs = chk.parentNode.parentNode.cells[1].getElementsByTagName("input");                                                  //通过父级节点获取输入框

    var status = chk.checked;                //判断复选框是否选中的变量

    for(var i=0,j=inputs.length;i<j;i++)            //遍历每个input控件

        inputs[i].disabled = status;             //通过复选框的值设置每个input控件的可用性

}

</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="chkOper(this)"/></td>

    <td width="230px">

      <input type="text" name="textfield" id="Text1" />

    </td>

    <td width="230px"><a href="http://www.youweishop.com">有为商城</a></td>

  </tr>

  <tr>

    <td align="center"><input type="checkbox" name="checkbox" id="Checkbox1"  onclick= "chkOper(this)"/></td>

    <td><input type="text" name="textfield2" id="textfield2" /></td>

    <td><a href="http://tg.youweishop.com">有为团购</a></td>

  </tr>

  <tr>

    <td align="center"><input type="checkbox" name="checkbox" id="Checkbox2" / onclick= "chkOper(this)"></td>

    <td><input type="text" name="textfield3" id="textfield3" /></td>

    <td><a href="http://news.youweishop.com">有为门户</a></td>

  </tr>

</table>

</body>

</html>

 

原创粉丝点击