<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title>文本框内显示提示文本 - www.jb200.com</title>  
<script src="jquery.js" type="text/
javascript"></script>  
<script type="text/javascript">  
function inputTipText(){
$("input[class*=grayTips]") //所有样式名中含有grayTips的input  
.each(function(){  
var oldVal=$(this).val();//默认的提示性文本  
$(this)  
.css({"color":"#888"})  //灰色  
.focus(function(){  
 if($(this).val()!=oldVal){$(this).css({"color":"#000"})}else{$(this).val("").css({"color":"#888"})}  
})  
.blur(function(){  
 if($(this).val()==""){$(this).val(oldVal).css({"color":"#888"})}  
})  
.keydown(function(){$(this).css({"color":"#000"})})  
})  
}  
  
$(function(){  
inputTipText();  //直接调用  
})  
</script>  
</head>  
<body>  
<input type="text" value="输入您的用户名" class="grayTips" />  
<input type="text" value="输入您的登录密码" class="aaagrayTips"/>  
</body>  
</html> 
function addLoadEvent(func){  
 var oldonload = window.onload;  
 if (typeof window.onload != 'function'){  
  window.onload = func;  
 }else{  
  window.onload = function(){  
oldonload();  
func();  
  }  
 }  
} 
function checkText(){  
 var textId = document.getElementById('test');  
 var textDefault = '请输入字符';  
 function cls(){  
  if (this.value == textDefault){  
this.value = '';  
  }  
 }  
 function res(){  
  if (this.value == ''){  
this.value = textDefault;  
  }  
 }  
 textId.onfocus = cls;  
 textId.onblur = res;  
}  
addLoadEvent (checkText); 
内容:<input id="test" type="text" value="请输入字符" />