日期:2014-05-17 浏览次数:20667 次
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
window.onload=function(){
//var name=document.getElementById("name");
var names=document.getElementsByTagName("input");
}
function validate(){
var input=document.getElementById("name");
var value=input.value;
//input.getAttribute("value");
if(/^[A-Za-z]{3,6}$/.test(value)){
//alert("输入正确");
msg.innerHTML="亲,输入不正确";
}else{
//alert("用户名错误");
msg.innerHTML="妹子,用户名错误"
}
}
function clearMsg(){
var msg=document.getElementById("msg");
msg.innerHTML="";
}
</script>
</head>
<body>
用户名:<input id="name" name="name" type="text" onblur="validate();" onfocus="clearMsg();">
<span id="msg"></span>
</body>
</html>