<!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>输入框的提示功能</title>
<script type="text/javascript" src="../js/jquery-1.4.2.js"></script>
<script type="text/javascript">
window.onload=function(){
$("#username").focusin(function(){
//this.value="";
//$(this).val()
if(this.value=="请输入用户名/邮箱/qq号...")
$(this).attr("value","");
}).focusout(function(){ //一个节点触发两个事件可以连写哦
//字符串处理,除去空格
var deleteblank = $.trim(this.value);
if(deleteblank==null || deleteblank==""){
//this.value="请输入用户名/邮箱/qq号...";
$(this).attr("value","请输入用户名/邮箱/qq号...");
}
});
}
</script>
</head>
<body>
请输入账号:<input type="text" id="username" value="请输入用户名/邮箱/qq号..." size=30/><br/><br/>
请输入密码:<input type="password" id="password" size=30/><br/><br/>
<input type="button" value="提交"/><br/>
</body>
</html>
效果: jquery 实现 ,当文本框得到焦点,提示语删除,移走之后显示提示语