<html >
<head>
    <title>无标题页</title>
    <script language="javascript">
     function change()
     {
     var chk=document.getElementById("chk");
     var txt=document.getElementById("txt");
     txt.disabled=true;
     if(chk.checked)
         txt.disabled=false;
     }
    </script>
</head>
<body >
    <table>
     <tr>
     <td>
      <input type="checkbox" id="chk"  onclick="change()"/>
      </td>
      <td>
      <input type="text" id="txt" disabled="true"/>
      </td>
     </tr>
    </table>
</body>
</html>

解决方案 »

  1.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
     <head>
      <title> New Document </title>
      <meta name="Generator" content="EditPlus">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
     </head> <body>
      <input id="id_chk" name="name_chk" type="checkbox" onclick="doSetTxt(this)" />&nbsp;change the input
      <br>
      <input id="id_txt" type="text" value="">
     </body>
    </html><script language="JavaScript">
    <!--
    document.getElementById("id_txt").disabled = true; function doSetTxt(obj)
    {
    if (obj.checked)
    {
    document.getElementById("id_txt").disabled = "";
    }
    else
    {
    document.getElementById("id_txt").disabled = true;
    }
    }
    //-->
    </script>
      

  2.   

    <input type= "checkbox" id= "chk" onclick="change()">
    <input type= "text" id= "txt" readOnly>function change(){
     var chk=document.getElementById("chk");
     var txt=document.forms[0].txt; if(chk.checked==true){
      txt.readOnly==false;
     }
    }
      

  3.   

    这里发帖子的时候,忘记选择html脚本标记了。
    正常运行的代码,在这里发帖的时候被加了很多
    空格,比如说<script   language= "JavaScript "> 
    这句,最开始写的时候,双引号里面只有javascript的,
    可是发完了以后就在后面多了个空格出来,这样
    当然无法运行。
    只好你自己把所有双引号里面的空格全都去掉再测试吧。
    实际上aaron81939097 所写的代码也能运行,也是需要
    把引号里面的空格去掉才成。
    唉,csdn上发帖子不如以前方便了,还要再选择一下是
    哪种code才能发好...
      

  4.   

    如果换成STRUTS标签还能运行不?好像不行的啊!呵呵!
      

  5.   

    <html>
      <head>
        <title>   New   Document   </title>
     <script   language="JavaScript" type="text/javascript">
    <!--function   setTxtState(obj)
    {
    if   (obj.checked)
    {
    document.getElementById( "chk ").disabled = "";
    }
    else
    {
    document.getElementById( "txt ").disabled =true;
    }
    }
    //-->
    </script>
      </head>
      <body>
        <input   id= "chk "   name= "name_chk " type="checkbox"   onclick= "setTxtState(this) "   /> 
        <br/>
        <input   id= "txt "   type= "text " visible="false"   value= ""/>
      </body>
    </html>