A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

  1. <%@ page language="java" import="java.util.*" pageEncoding="utf-8" contentType="text/html"%>
  2. <%
  3. String path = request.getContextPath();
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  5. %>

  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  7. <html>
  8.    <head>
  9.      <base href="<%=basePath%>">
  10.      
  11.     <title>登录界面</title>
  12.      
  13.     <meta http-equiv="pragma" content="no-cache">
  14.      <meta http-equiv="cache-control" content="no-cache">
  15.      <meta http-equiv="expires" content="0">   
  16.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  17.      <meta http-equiv="description" content="This is my page">
  18.      <!--
  19.      <link rel="stylesheet" type="text/css" href="styles.css">
  20.      -->

  21.   </head>
  22.    <script language="JavaScript">
  23. function Validate()
  24. {
  25. //得到用户 输入的信息  
  26. userid=form.userid.value;
  27. userpass=form.userpass.value;
  28. //判断用户名的长度
  29.     if(!maxLength(userid,12))
  30.          {
  31.          alert("拥护名长度大于12!");
  32.          form.userid.focuse();
  33.          return false;
  34.          }
  35.      
  36.     if(!maxLength(userpass,12))
  37.          {
  38.          alert("密码长度大于12!");
  39.          form.userpass.focuse();
  40.          return false;
  41.          }
  42.      
  43.     //判断拥护名和密码是否一致
  44.     if(userid==userpass)
  45.          {
  46.          alert("拥护名和密码不能相同");
  47.          form.userpass.focuse();
  48.          return false;
  49.          }
  50. return true;
  51. }
  52. //验证是否满足最小长度
  53. function minLength(str,length)
  54.      {
  55.      if(str.length>=length)
  56.          return true;
  57.      else
  58.          return false;     
  59.      }
  60. function maxLength(str,length)
  61.      {
  62.      if(str.length<=length)
  63.          return true;
  64.      else
  65.          return false;     
  66.      }
  67.      
  68.       window.open("http://www.baidu.com","window2")
  69.       
  70. </script>
  71.    <body>
  72. <form action="MyJsp2.jsp" onsubmit="return Validate();" method="post">
  73. 用户名:<input type="text" name="userid"><br>
  74. 密码:<input type="password" name="userpass"><br>
  75. <input type="reset" value="重填" >
  76.    <input type="submit" value="确定">
  77. </form>
  78.    </body>
  79. </html>
复制代码
上来是代码。。。

1 个回复

倒序浏览
出现什么错?我只是觉得,你有两个function:minLength 、maxLength ,只用了一个,而(!maxLength(userid,12)),不是等同 (minLength(userid,12)) 吗?minLength 是“>=”,maxLength 是“<=”,是否搞反了?

评分

参与人数 1技术分 +1 收起 理由
admin + 1 黄秋童鞋一直很热心,大家学习学习!.

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马