<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>失去焦点触发事件</title>
<script>
function myfunction(){
var x = document.getElementById("input1");
c = /^[a-zA-Z0-9]{6,8}$/;
if((x.value).match(c)){
alert("输入正确!");
w.style.display="none";
}
else if((x.value)==""){
alert("请输入!");
}
else{
alert("错误!");
x.value = "";
}
}
</script>
<script>
function ttt(){
var w = document.getElementById("p1");
w.style.display="block";
}
</script>
</head>
<body>
<input type="text" id="input1" onblur="myfunction()" onclick="ttt()" />
<p id="p1" style="display: none;color: red;">请输入6-8位数字和字母的组合!</p>
</body>
</html>