主要是document.getElementById("userName").innerHTML="请输入用户名";
改成 document.getElementById("a").innerHTML="请输入用户名";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
</head>
<script>
function check_userName(){
if (document.getElementById("userName").value==""){
document.getElementById("a").innerHTML="请输入用户名";
document.getElementById("a").style.background="#ee00ee";
return false;
}else{
document.getElementById("a").innerHTML="";
document.getElementById("userName").style.background="";
return true;
}
} function check_password(){
if (document.getElementById("password").value==""){
document.getElementById("b").innerHTML="密码不能为空";
document.getElementById("password").style.background="#ee00ee";
return false;
}else{
document.getElementById("b").innerHTML="";
document.getElementById("password").style.background="";
return true;
}
}
function check_password1(){
check_password();
if (document.getElementById("password1").value!=document.getElementById("password").value){
document.getElementById("c").innerHTML="两次输入的密码不相同!";
document.getElementById("password1").style.background="#ee00ee";
return false;
}else{
document.getElementById("c").innerHTML="";
document.getElementById("password1").style.background="";
return true;
}
} function check(){
return (check_userName()&& check_password() && check_password1());
} </script>
<body>
<form id="form1" name="form1" method="post" action="hhh.htm#" onsubmit="return check()">
<br/> <input type="text" id="userName" name="userName" value="" onblur="check_userName()"> <span id="a"> </span>
<br/> <input type="password" id="password" name="password" value="" onblur="check_password()"> <span id="b"> </span>
<br/> <input type="password" id="password1" name="password1" value="" onblur="check_password1()"> <span id="c"> </span>
<br/>
<input type="submit">
</form> </body>
</html>
改成 document.getElementById("a").innerHTML="请输入用户名";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
</head>
<script>
function check_userName(){
if (document.getElementById("userName").value==""){
document.getElementById("a").innerHTML="请输入用户名";
document.getElementById("a").style.background="#ee00ee";
return false;
}else{
document.getElementById("a").innerHTML="";
document.getElementById("userName").style.background="";
return true;
}
} function check_password(){
if (document.getElementById("password").value==""){
document.getElementById("b").innerHTML="密码不能为空";
document.getElementById("password").style.background="#ee00ee";
return false;
}else{
document.getElementById("b").innerHTML="";
document.getElementById("password").style.background="";
return true;
}
}
function check_password1(){
check_password();
if (document.getElementById("password1").value!=document.getElementById("password").value){
document.getElementById("c").innerHTML="两次输入的密码不相同!";
document.getElementById("password1").style.background="#ee00ee";
return false;
}else{
document.getElementById("c").innerHTML="";
document.getElementById("password1").style.background="";
return true;
}
} function check(){
return (check_userName()&& check_password() && check_password1());
} </script>
<body>
<form id="form1" name="form1" method="post" action="hhh.htm#" onsubmit="return check()">
<br/> <input type="text" id="userName" name="userName" value="" onblur="check_userName()"> <span id="a"> </span>
<br/> <input type="password" id="password" name="password" value="" onblur="check_password()"> <span id="b"> </span>
<br/> <input type="password" id="password1" name="password1" value="" onblur="check_password1()"> <span id="c"> </span>
<br/>
<input type="submit">
</form> </body>
</html>
高手就是不一样