编写了一个函数,想限制字符长度,可是一直不成功,请教高手啊~~
function lengthless(username,4)
{
 if(window.document.form1.username.value.length<4)
 {
  window.alert("不能少于4位!");
  document.form1.username.focus();
  return false;
 }
 return true;
}调用的时候:onBlur="return lengthless(username,4);"请大家指教~!

解决方案 »

  1.   

    <html>
    <head>
    <script language="JavaScript" type="text/javascript"> 
    function lengthless(username,s) {
    if(username.length <4 ){
    window.alert("不能少于4位!"); 
    document.form1.username.value="";
    document.form1.username.focus(); 
    return false;
    }
    return true;
    }
    </script> 
    </hrad> 
    <body> 
    <form method="post" name="form1"> 
    <input type="text" name="username" onBlur="return lengthless(this.value,'4');" >
    </form> 
    </body> 
    </html>