JavaScript --onfocus,onblur实现简单注册密码案例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript">
function fun1(){
var pwd1 = document.getElementById("one").value;
if(pwd1==''){
document.getElementById("one").focus();
document.getElementById("xxxx").innerHTML="未设置密码";
}else{
document.getElementById("xxxx").innerHTML="*";
}
}
function fun2(){
var pwd1 = document.getElementById("one").value;
var pwd2 = document.getElementById("two").value;
if(pwd1 != pwd2){
document.getElementById("two").focus();
document.getElementById("cc").innerHTML="两次密码内容不一致";
}else{
document.getElementById("cc").innerHTML="*";
}
}
</script>
</head>
<body>
<center>
<table border="2">
<tr>
<td>用户名</td>
<td><input type="text"></td>
</tr>
<tr>
<td>密码</td>
<td><input type="text" id="one">
<font style="color:red" id="xxxx">*</font>
</td>
</tr>
<tr>
<td>重复密码</td>
<td><input type="text" id="two" onfocus="window.fun1()" onblur="window.fun2()">
<font style="color:red" id="cc">*</font>
</td>
</tr>
<tr>
<td>用户邮箱</td>
<td><input type="text"></td>
</tr>
</table>
</center>
</body>
</html>