直接贴代码了!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>文本框特效</title>
<style>
.searchinp{padding:2px 2px;height:17px;width:290px;font-size:12px;}
.f_000{color:#000;}
.f_999{color:#999;}
</style>
<script>
function $(objectId) {
if(document.getElementById && document.getElementById(objectId)) {
return document.getElementById(objectId);// W3C DOM
} else if (document.all && document.all(objectId)) {
return document.all(objectId);// MSIE 4 DOM
} else if (document.layers && document.layers[objectId]) {
return document.layers[objectId];// NN 4 DOM.. note: this won't find nested layers
} else {
return false;
}
}
function addEvt(tab)
{
$(tab).className="searchinp f_999";
$(tab).onclick =function std()
{
if($(tab).value=="请输入您的问题关键词 比如:‘忘记密码’?")
{
$(tab).className="searchinp";
$(tab).value="";
}
}
$(tab).onblur =function std()
{
var str=$(tab);
if(str.value.length==0)
{
$(tab).className="searchinp f_999";
str.value="请输入您的问题关键词 比如:‘忘记密码’?";
}
}
}
</script>
</head>
<body>
<input value="请输入您的问题关键词 比如:‘忘记密码’?" id="search_content" type="text" class="searchinp f_999">
<script>addEvt("search_content");</script>
</body>
</html>