javaScript文本框信息驗證

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>無標題文檔</title>
<script type="text/javascript">
function checkText(){
 var name = document.getElementById("name").value;
 var passwd = document.getElementById("passwd").value;
 if(name == "") {
  alert("用戶名不能爲空!");
  //elem.focus();
  return false;
 }
 if(passwd.length < 6){
  alert("密碼長度過短,長度必須大於6!");
  //elem.focus();
  return false;
 }
 return true;
}
</script>
</head>javascript

<body>
<form name="form1" method="post" action="">
用戶名:<input type="text" name="name" id="name" onBlur="return checkText()"><br/>
密 碼:<input type="password" name="passwd" id="passwd" onBlur="return checkText()"><br/>
    <input type="submit" name="Submit" value="提交">&nbsp;
    <input type="submit" name="Submit2" value="重置" onClick="reset()">
</form>
</body>
</html>html

相關文章
相關標籤/搜索