问题描述
- jsp新人求助,登录页面设定验证码和密码确认之后,在表单内提交前校验完全没响应
-
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%> <%@ page import = "java.util.*" %> <%@ page import = "util.*" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>登录页面</title> <script language = "JavaScript" type = "text/javascript"> // (function(){ // var sub = document.getElementById("sub"); //初始化移入移出事件 //if(sub.addEventListener){ //sub.addEventListener("click", check); //}else if(sub.attachEvent){ // sub.attachEvent("onClick", check); //} //})(); function check(f){ var pwd = f.upass.value; var acpwd = f.acupass.value; var vc = f.yanzheng.value; var vcode = f.img.value; boolean ret = true; if(pwd != acpwd){ alert("两次密码不相同!!!"); ret = false; window.location.reload; }else if(vcode != vc)){ alert("验证码不对!!!"); ret = false; window.location.reload; }else{ document.forms[0].submit(); } return ret; } </script> <body> <from action = "LoginServ" method = "post" name = "loginform" onSubmit = "return check(this)"> 用户名: <input type="text" name="id"/><br/> 密 码: <input type="password" name="upass" id="upass"/><br/> 确认密码:<input type="password" name="acupass" id="acupass"/><br/> 验证码: <input type="text" name="excode" id="yanzheng"/> <% Tools t = new Tools(); String vcode = t.ExperimentCode(); %> <img src="/WebBook/images/vcode.png" id = "img"/><br/> <input type="radio" name="identity" value="con" checked="checked" />买家 <input type="radio" name="identity" value="sel" />卖家 <input id = "sub" type="submit" value="登录"/> <input type="reset" value="清空"/> </from> </body> </html>
解决方案
语法都错了,js和java混用了
function check(f) {
var pwd = f.upass.value;
var acpwd = f.acupass.value;
var vc = f.yanzheng.value;
var vcode = f.img.value;
var ret = true;///js没有boolean关键字
if (pwd != acpwd) {
alert("两次密码不相同!!!");
ret = false;
window.location.reload;
} else if (vcode != vc)/*)这里多了个反括号*/ {
alert("验证码不对!!!");
ret = false;
window.location.reload;
} else {
document.forms[0].submit();
}
return ret;
}
解决方案二:
去检查jquery语法
时间: 2024-10-04 12:31:24