<form onsubmit="return checkForm()">
<input type="password" name="password" id="password"/>
</form>
<script>
function checkForm(){
  if(document.getElementById("password").value.length<6){
    alert("Password length must large the 6");
    return false;  
  }
  return true;
}
</script>

解决方案 »

  1.   

    楼上的谢谢,我刚才没有说明白,我原先有个form,且下面有两个按钮,一个确认,取消。原先在输入完密码后,光标移动到确认按钮上也可以判断。现在客户提出加上在密码框上输入密码后再按确认直接判断的功能,原先的功能还是要存在的。
      

  2.   

    <form onsubmit="return checkForm()">
    <input type="password" name="password" id="password" onBlur="checkPassword()"/>
    </form><script>
    function checkPassword(){
      if(document.getElementById("password").value.length<6){
        alert("Password length must large the 6");
        document.getElementById("password").focus();
        return false;  
      }
      return true;
    }
    </script>当password失去焦点的时候调用那个检测程序,当然function就换一个名字吧,不经不是checkForm了!