<td bgcolor="#E8DBE8">
           <div align="center">&nbsp;
           <select name="txt_phonesol">
                  <option value="0">readonly</option>
                  <option value="1">text</option>
              </select>
           </div></td>
          
           <td><div align="center"><input name="txt_tcreason" type=text></div></td>
          
          
          
选择框控制文本框,当我选择readonly是  文本框是readonly的   当我选择text,文本框是可写的谢谢  初学  线等

解决方案 »

  1.   


    <td bgcolor="#E8DBE8">
      <div align="center">&nbsp;
      <select name="txt_phonesol" onchange="javascript:document.getElementById('txt_tcreason').readOnly=(this.value==0)">
      <option value="0">readonly</option>
      <option value="1">text</option>
      </select>
      </div></td>
      
      <td><div align="center"><input name="txt_tcreason" type=text></div></td>
      

  2.   

    <td bgcolor="#E8DBE8">
      <div align="center">&nbsp;
      <select name="txt_phonesol" onchange="javascript:document.getElementById('txt_tcreason').type=this.value">
      <option value="readonly">readonly</option>
      <option value="text">text</option>
      </select>
      </div></td>
      
      <td><div align="center"><input name="txt_tcreason" type=text></div></td>
      

  3.   

    <!--补充1楼代码,少了ID-->
    <div align="center"><input name="txt_tcreason" type=text id="txt_tcreason"></div><
      

  4.   

    恩,可以了,还有一个问题就是第一次打开不是readonly的  
      

  5.   

    <!--默认为readonly你加个属性就行了-->
    <input name="txt_tcreason" type=text id="txt_tcreason" readonly="readonly"/>
      

  6.   


    <!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>
      <title> new document </title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
      <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
     </head> <body>
      <select name="txt_phonesol" id="txt_phonesol">
      <option value="0">readonly</option>
      <option value="1">text</option>
      </select><input name="txt_tcreason" type='text' id="txt_tcreason"></div>
    <script type="text/javascript">
    function $(id) {
    return typeof id === 'string' ? document.getElementById(id) : id;
    } $("txt_phonesol").onchange = function() {
    var iptElem = $('txt_tcreason'); if(this.value == "1") {
    iptElem.removeAttribute("readOnly");
    iptElem.focus();
    iptElem.style.backgroundColor = '#FFFFFF';
    } else {
    iptElem.setAttribute("readOnly", true);
    iptElem.style.backgroundColor = '#CCCCCC';
    }
    } $("txt_phonesol").onchange();
    </script>
     </body>
    </html>