1.光标离开登录名文本,显示“请输入用户名”
2.光标focus登录名,显示“”空
3.直接点确认修改,显示“用户名不能空”,拒绝提交表单
4.直接点确认修改,显示“密码不能空”,拒绝提交表单
5.直接点确认修改,显示“请验证密码”,拒绝提交表单
6.两次密码一样,离开光标 , 显示ok
7.直接点确认修改,显示“请输入邮箱”,拒绝提交表单
8.全部输入,点击确认修改,提交成功
9.忘了一点,两次密码不一样,离开光标,显示“两次密码不匹配”
10.补充,两次密码不一样,点击确认修改,表单拒绝提交
js代码:在/js/student_modify.js文件中
function nameBlur() {
if ("" == document.getElementById("username").value
|| "请输入用户名" == document.getElementById("username").value) {
document.getElementById("username").value = "请输入用户名";
}
}
function nameFocus() {
if ("请输入用户名" == document.getElementById("username").value) {
document.getElementById("username").value = "";
}
}
function modifySubmit() {
if ("" == document.getElementById("username").value
|| "请输入用户名" == document.getElementById("username").value) {
document.getElementById("usernameMsg").innerHTML="用户名不能空";
document.getElementById("password1Msg").innerHTML="";
document.getElementById("password2Msg").innerHTML="";
document.getElementById("emailMsg").innerHTML="";
document.getElementById("username").focus();
return false;
}
if ("" == document.getElementById("password1").value) {
document.getElementById("usernameMsg").innerHTML="";
document.getElementById("password1Msg").innerHTML="密码不能空"
document.getElementById("password2Msg").innerHTML="";
document.getElementById("emailMsg").innerHTML="";
document.getElementById("password1").focus();
return false;
}
if ("" == document.getElementById("password2").value) {
document.getElementById("usernameMsg").innerHTML="";
document.getElementById("password1Msg").innerHTML="";
document.getElementById("password2Msg").innerHTML="请验证密码";
document.getElementById("emailMsg").innerHTML="";
document.getElementById("password2").focus();
return false;
}
if ("" == document.getElementById("email").value) {
document.getElementById("usernameMsg").innerHTML="";
document.getElementById("password1Msg").innerHTML="";
document.getElementById("password2Msg").innerHTML="";
document.getElementById("emailMsg").innerHTML="请输入邮箱"
document.getElementById("email").focus();
return false;
}
if (""!= document.getElementById("password1").value
&& document.getElementById("password2").value!=document.getElementById("password1").value) {
document.getElementById("usernameMsg").innerHTML="";
document.getElementById("password1Msg").innerHTML="";
document.getElementById("password2Msg").innerHTML="两次密码不匹配";
document.getElementById("emailMsg").innerHTML="";
document.getElementById("password2").focus();
return false;
}
}
function passwordBlur2() {
if ("" == document.getElementById("password2").value) {
document.getElementById("registPasswordMsg2").innerHTML="请确认密码。";
}
//两次密码不同,就显示不同
if (""!= document.getElementById("password1").value
&& document.getElementById("password2").value!=document.getElementById("password1").value) {
document.getElementById("password2Msg").innerHTML="两次密码不匹配";
}
//两次密码一样,就显示ok
if (""!= document.getElementById("password1").value
&& document.getElementById("password2").value==document.getElementById("password1").value) {
document.getElementById("password2Msg").innerHTML="OK";
}
}
网页jsp代码:
method="post" οnsubmit="return modifySubmit();">
登陆名 | οnblur="nameBlur();" οnfοcus="nameFocus()"/> | |
新密码 | ||
确认密码 | id="password2" οnblur="passwordBlur2();"/> | |
邮箱 | ||