JavaScript 最佳表单验证
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>注册会员</title>
<style type="text/css">
.table {
border-collapse:collapse;
font-size:12px;
}
.input {
width:200px;
height:22px;
}
.stats1 {
color:#aaa;
}
.stats2 {
color:#000;
}
.stats3 {
color:red;
}
.stats4 {
color:green;
}
</style>
</head>
<body>
<form action="index.php" method="post" onSubmit="return regCheck('click')">
<table border="0" align="center" width="500" class="table">
<tr>
<td width="80" height="25" align="right">用户名称:</td><td><input type="text" name="username" value="" class="input" /> <span class="stats1"></span></td>
</tr>
<tr>
<td width="80" height="25" align="right">密码:</td><td><input type="password" name="password" value="" class="input" /> <span class="stats1"></span></td>
</tr>
<tr>
<td width="80" height="25" align="right">确认密码:</td><td><input type="password" name="repass" value="" class="input" /> <span class="stats1"></span></td>
</tr>
<tr>
<td width="80" height="25" align="right">电子邮箱:</td><td><input type="text" name="email" value="" class="input" /> <span class="stats1"></span></td>
</tr>
<tr>
<td height="30"></td><td align="left"><input type="submit" name="send" value="提交" /> <input type="reset" value="重置" /></td>
</tr>
</table>
</form>
</body>
</html>
<script language="javascript">
// 找到 input 后面的 SPAN 标签
function gspan(cobj){
while(true){
if(cobj.nextSibling.nodeName!="SPAN")
cobj=cobj.nextSibling;
else
return cobj.nextSibling;
}
}
function check(obj, info, fun, click){
var sp=gspan(obj);
obj.onfocus=function(){
sp.innerHTML=info;
sp.className="stats2";
}
obj.onblur=function(){
if(fun(this.value)){
sp.innerHTML="输入正确√";
sp.className="stats4";
}else{
sp.innerHTML=info;
sp.className="stats3";
}
}
if(click=="click")
&nbs
补充:web前端 , JavaScript ,