描述
获得焦点和失去焦点事件的应用
代码
.info{
color:#888888;
}
.error{
color: red;
}
.right{
color: white;
background-color: greenyellow;
display: inline-block;
height: 20px;
width: 20px;
border-radius: 20px;
}
function show(){
document.getElementById("info").innerHTML="请输入11位手机号";
document.getElementById("info").className="info";
}
function check(obj){
var tel = obj.value;
if(tel.length == 11){
document.getElementById("info").innerHTML="nice";
document.getElementById("info").className="right";
}else{
document.getElementById("info").innerHTML="长度为11位";
document.getElementById("info").className="error";
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="js/index4.js"></script>
<link rel="stylesheet" href="css/index4.css"/>
</head>
<body>
焦点事件:
<input type="text" onfocus="show()" onblur="check(this)"/><span id="info" ></span>
</body>
</html>