代码一:
value="请输入你要搜索的关键词" οnfοcus="if (this.value=='请输入你要搜索的关键词') this.value='';"
代码二:
value="请输入你要搜索的关键词" οnblur="if(this.value==''){this.value='请输入你要搜索的关键词'}" οnfοcus="this.value=''"
value="请输入你要搜索的关键词" οnfοcus="if (value =='请输入你要搜索的关键词'){value =''}" οnblur="if (value ==''){value='请输入你要搜索的关键词'}"
例如:
<form name="frmsearch" id="frmsearch" action="/search/" method="post">
<input type="text" id="Key" name="Key" maxlength="120" style="width:125px;" title="关键字" value="关键字" οnfοcus="if (this.value=='关键字') this.value=''" />
<input type="submit" value="" />
</form>
金山毒霸的一段代码:
<INPUT οnblur="if (value ==''){value='金山毒霸6最新版'}" οnmοuseοver=this.focus() οnfοcus=this.select() οnclick="if(this.value=='金山毒霸6最新版')this.value=''" maxLength=40 size=16 value=金山毒霸6最新版 name=ss_name>
另外一种
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>鼠标提示</title>
<script language="JavaScript">
function seashowtip(tips,flag,iwidth){
var my_tips=document.all.mytips;
if(flag){
my_tips.innerHTML=tips;
my_tips.style.display="";
my_tips.style.width=iwidth;
my_tips.style.left=event.clientX+10+document.body.scrollLeft;
my_tips.style.top=event.clientY+10+document.body.scrollTop;
}
else
{
my_tips.style.display="none";
}
}
</script>
<style>
body{font-size:12px}
</style>
<div id=mytips style="position:absolute;background-color:#ffffff;width:121;height:16;border:1px solid gray;display:none;filter: progid:DXImageTransform.Microsoft.Shadow(color=#999999,direction=135,strength=3); left:0; top:5"></div>
</head>
<body>
<form name="form1" method="post" action="">
用户名:
<input type="text" name="textfield" tips="*** 输入用户名." οnmοusemοve=seashowtip(this.tips,1,150) οnmοuseοut=seashowtip(this.tips,0,150)>
<br/>
密 码:
<input type="text" name="textfield2" tips="*** 输入密码." οnmοusemοve=seashowtip(this.tips,1,150) οnmοuseοut=seashowtip(this.tips,0,150)>
<br/>
验证码:
<input type="text" name="textfield3" tips="*** 输入验证码." οnmοusemοve=seashowtip(this.tips,1,150) οnmοuseοut=seashowtip(this.tips,0,150)>
<input type="submit" name="Submit" value="提交">
</form>
</body>
</html>