<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="content-type"
content="text/html;charset=utf-8" />
<script>
function txtfocus(){
var
mytxt=document.getElementById("txt");
if(mytxt.value=="请输入用户名"){
mytxt.value="";
mytxt.style.color="#121212";
}
}
function
txtonblur(){
var mytxt=document.getElementById("txt");
if(mytxt.value==""){
mytxt.value=mytxt.defaultValue;
mytxt.style.color="#c7d1cc";
}else
if(mytxt.value.length<10){
alert("姓名长度应该大于10个字符");
}
}
</script>
</head>
<body>
<input id="txt"
type="text"value="请输入用户名" style="color:#c7d1cc" onfocus="txtfocus()"
onBlur="txtonblur()"/>
<input type="text" id="mytxt" />
</body>
</html>
原文:http://www.cnblogs.com/jiablog/p/3653751.html