日期:2014-05-16 浏览次数:20285 次
<input type="text" value="请输入关键字" onblur="if (value ==''){value='请输入关键字'}" onfocus="if (value =='请输入关键字'){value =''}" name="key">
------解决方案--------------------
<input type="text" value="请输入关键字"
onfocus="this.value = this.value == this.defaultValue ? '' : this.value;"
onblur="this.value = this.value == '' ? this.defaultValue : this.value;" />
------解决方案--------------------
<title>无标题文档</title>
<script type="text/javascript">
function init(){
var username=document.getElementById("username");
var password=document.getElementById("password");
username.first=true;
password.first=true;
if(username.addEventListener){
username.addEventListener("focus",ss,false);
password.addEventListener("focus",ss,false);
}else if(username.attachEvent){
username.attachEvent("onfocus",ss);
password.attachEvent("onfocus",ss);
}
}
function ss(e){
var a=e||window.event;
if(a.srcElement){
if(a.srcElement.first){
a.srcElement.value="";
a.srcElement.first=false;
a.srcElement.style.color="black";
}
}else if(a.currentTarget){
if(a.currentTarget.first)
a.currentTarget.value="";
a.currentTarget.first=false;
a.currentTarget.style.color="black";
}
}
</script>
</head>
<body onload="init()">
<input type="text" value="请输入用户名"id="username" style="color:#999">
<input type="password" value="请输入密码" id="password" style="color:#999">
</body>
</html>
这样试试