实现功能如下:
在页面上有个下拉框(下拉框有几中不同的选项:帐号,密码)和一个输入框,还有一个提交按钮。选择不同的选项有不同输入框,限制输入框中输入字节个数。比如账号框中只能输入20个字节,密码框中只能输入10个字节。

解决方案 »

  1.   


    <select id='s1' onchange='setLength()'>
      <option value='10'>密码</option>
      <option value='20'>账号</option>
    </select>
    <input id='t1' type='text'>function setLength()
    {
      document.getElementById('t1').maxLegnth = document.getElementById('s1').value;
    }
      

  2.   

    <script>
    function Changesel(){
      var traget=document.getElementById("A1");
       if (document.frm.lx.value=="GE"){
           traget.style.display="";
      }else{
           traget.style.display="none";
    }
    }
    </script>
    <form name="frm" id="frm">
    <select name="lx" onChange="Changesel()">
          <option value="GE">user</option>
          <option value="QT">pwd</option>
    </select>
    <input name="A1" type="text" >
    </form>
      

  3.   

    var str=document.getElementById("id").options;
    var value=str[document.getElementById("id").selectedIndex].text;
    var txt=document.createElement("input");
    txt.setAttribute("type","text");
    if(value=="账号"){
       txt.setAttribute("maxlength","20");
    }
    else{......,"10"}
    document.body.insertBefore(txt,document.getElementById("button"));
      

  4.   

    提示信息:<selectid='s1' onchange='setLength()'>
    <optionvalue='10'>密码 </option> 
    <optionvalue='20'>账号 </option> 
    </select> 
    <input id='tbContent' type='text'><span id="SPANMsg"></span>
    var DDLOp=document.getElementById('s1');
    var SPANMsg=document.getElementById('SPANMsg');
    function setLength()
    {
      s1value=document.getElementById('s1').value;
      document.getElementById('t1').maxLegnth = s1value;
      if(s1value=='10'){msg="<font color=red>密码长度为10</font>";}
      else{msg="<font color=red>帐号长度为20</font>";}
      SPANMsg.innerHTML=msg;
    }