/* 试用 Javascript来实现通用的登录验证功能 *实现简单 *代码少 适用于简单的JSP页面管理* * */
<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function checkform(myform){
for(i=0;i<myform.length;i++){
if(myform.elements[i].value==""){
alert(myform.elements[i].title+"不能为空!");
myform.elements[i].focus();
return false;
}
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="" name="form1" method="post" onSubmit="return checkform(form1)">
<table>
<tr>
<td>用户名:<input name="name" title="用户名" type="text"></td>
<td>密 码:<input name="pwd" title="密码" type="password"></td>
</tr>
<tr>
<td colspan="2">邮 箱<input name="email" title="邮箱" type="text" ></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="提交"></td>
<td><input type="reset" name="Reset" value="重置"></td>
</tr>
</table>
</form>
</body>
</html>
pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function checkform(myform){
for(i=0;i<myform.length;i++){
if(myform.elements[i].value==""){
alert(myform.elements[i].title+"不能为空!");
myform.elements[i].focus();
return false;
}
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="" name="form1" method="post" onSubmit="return checkform(form1)">
<table>
<tr>
<td>用户名:<input name="name" title="用户名" type="text"></td>
<td>密 码:<input name="pwd" title="密码" type="password"></td>
</tr>
<tr>
<td colspan="2">邮 箱<input name="email" title="邮箱" type="text" ></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="提交"></td>
<td><input type="reset" name="Reset" value="重置"></td>
</tr>
</table>
</form>
</body>
</html>
转载于:https://blog.51cto.com/baoantao/388514