首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

大家帮小弟我看看小弟我这个js表单验证如何错了呢?点击没有反应,多谢了

2012-04-14 
大家帮我看看我这个js表单验证怎么错了呢?点击没有反应,谢谢了%@ page languagejava importjava.uti

大家帮我看看我这个js表单验证怎么错了呢?点击没有反应,谢谢了
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <base href="<%=basePath%>">
   
  <title>My JSP 'register.jsp' starting page</title>
   
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
  body {background-color:#333333}


  table.one
  {
  table-layout: fixed;
background-color:#0033FF;
border:none;
border-style:none;


 

 
  }


#yellow{
color:#FFFF00
}

#red{
color:#FF0000
}


#Layer1 {
position:relative;
width:700px;
height:800px;
z-index:1;
left: 337px;
top: 0px;
background-image:url(02.jpg);

}
  #Layer2 {
position:relative;
width:200px;
height:115px;
z-index:2;
left: 181px;
top: 66px;


}

  
  </style>
<script language="javascript">
function yanzheng()
{  
  if (CheckName()&&CheckPwd()&&onlyid())
  {  
  return true;
  }
  return false;
}





function CheckName()
{
  var name=document.form1.username;
  if (name.value.length==0)
  {
  window.alert("用户名不能为空!");
  name.focus();
  return false;
  }

  if(!/^\w{3,8}$/.test(name.value))
{
window. alert("用户名必须为3到8位(数字字母下划线)");
name.select();
return false;
}

  return true;
}
function CheckPwd()
{
  var pwd=document.form1.password; 
  if (pwd.value.length==0)
  {
  window.alert("密码不能为空!");
  pwd.focus();
  return false;
  }
  if (!/^\w{6,12}$/.test(pwd.value))
  {
  window.alert("密码长度在6到12位!");
  pwd.select();
  return false;
  }
  return true;
}

function onlyid()
{
var uid=document.form1.userid; 
 
 if (uid1.value.length==0)
  {
  window.alert("唯一标识不可为空!");
  uid1.focus();
  return false;
  }



return true;
}
</script>

  </head>
  
  
  <body>
  <div id="Layer1">
<div id="Layer2">
<form action="denglu.action" method="post" onSubmit="return yanzheng()" name="form1">
 
  <table width="337" height="132" class="one" >


  <tr>
  <td width="69"><font id="yellow"> 用户名:</font></td>
  <td width="252"><input type="text" name="username"/></td>
  </tr>
  <tr>
  <td>&nbsp;</td>
  <td><font id="red">用户名由字母或数字或下划线组成(3到8位)</font></td>
  </tr>
  <tr>
  <td><font id="yellow"> 密码:</font></td>
  <td><input type="password" name="password"/></td>
  </tr>
  <tr>
  <td>&nbsp;</td>
  <td><font id="red">密码(6到12位)</font></td>
  </tr>
<tr>
  <td><font id="yellow"> 你的ID(不可以变的):</font></td>
  <td><input type="text" name="userid"/></td>
  </tr>
  <tr>
  <td>&nbsp;</td>
  <td><font id="red">您的唯一标识请勿修改</font></td>
  </tr>

  <tr>
  <td height="19" colspan="2" valign="middle">
  <div align="center"> 
  <input type="submit" value="更改" /></div>  
   
  </td>
</tr>
<tr>
  <td colspan="2" class="tt"> <div align="center"> <input type="reset" value="重置"/></div> </td>
  </tr>
  </table>
  </form>






</div>
  </div>
  
  </body>
  
  
  
</html>


[解决办法]
var uid=document.form1.userid; 
 
 if (uid1.value.length==0)
{
window.alert("唯一标识不可为空!");
uid1.focus();
return false;
}
uid1 写错了

[解决办法]
function yanzheng()
{
if (CheckName()&&CheckPwd()&&onlyid())
{
return true;
}else{
return false;
}
}

热点排行