jsp登录
1.<BUTTON style="HEIGHT:25px" onClick="javascript:location.href='main.jsp'" name="submit">
2.<form action="updateServlet.do" method="post" id="form"
onSubmit="return subTest();"></form>
3.<input type="button" value="提交" onClick="subTest()">
subTest();是js里的验证
var kong = /^$/;
function pwTest1() {
var password = document.getElementById("password").value; // 传的是id的值
var passw = document.getElementById("passw");
var ymsz = /^[0-9A-Za-z]+$/;
if (kong.test(password)) {
passw.style.color = "red";
passw.innerHTML = " × 密码不可以为空";
return false;
} else if (ymsz.test(password)) {
passw.style.color = "green";
passw.innerHTML = " √ ";
return true;
} else {
passw.style.color = "red";
passw.innerHTML = " × 密码格式不正确 ";
return false;
}
}
function pwTest2() {
var ur_password = document.getElementById("ur_password").value;
var pass = document.getElementById("pass");
var ymsz = /^[0-9A-Za-z]+$/;
if (kong.test(ur_password)) {
pass.style.color = "red";
pass.innerHTML = " × 密码不可以为空";
return false;
} else if (ymsz.test(ur_password)) {
pass.style.color = "green";
pass.innerHTML = " √ ";
return true;
} else {
pass.style.color = "red";
pass.innerHTML = " × 密码格式不正确 ";
return false;
}
}
function pwTest3() {
var repassword = document.getElementById("repassword").value;
var cfpass = document.getElementById("cfpass");
var ymsz = /^[0-9A-Za-z]+$/;
if (kong.test(repassword)) {
cfpass.style.color = "red";
cfpass.innerHTML = " × 密码不可以为空";
return false;
} else if (ymsz.test(repassword)) {
cfpass.style.color = "green";
cfpass.innerHTML = " √ ";
return true;
} else {
cfpass.style.color = "red";
cfpass.innerHTML = " × 密码格式不正确 ";
return false;
}
}
function subTest() {
var password = document.getElementById("password").value;
var urpassword = document.getElementById("ur_password").value;
var repassword = document.getElementById("repassword").value;
var mm = /^[0-9a-zA-Z]{2,10}$/;
var flag = true;
if (urpassword == "") {
alert("新密码不能空");
flag = false;
} else if (!mm.test(urpassword)) {
alert("密碼格式不正確");
flag = false;
} else if (urpassword != repassword) {
alert("两次输入的密码不一致");
flag = false;
}
if (flag) {
document.getElementById("form").submit();
}
}