HTML DOM focus()和blur()方法 输入框鼠标指过自动消失鼠标离开显示 js
http://blog.csdn.net/zyxlinux888/article/details/7391240
定义和用法
focus() 方法用于在密码域上设置焦点。
语法
passwordObject.focus()
实例
下面的例子可设置或移开密码域上的焦点:
<html> <head> <script type="text/javascript"> function setFocus() { document.getElementById('password1').focus() } function loseFocus() { document.getElementById('password1').blur() } </script> </head> <body> <form> <input type="password" id="password1" value="thgrt456" /> <input type="button" onclick="setFocus()" value="Set focus" /> <input type="button" onclick="loseFocus()" value="Lose focus" /> </form> </body> </html>实例2:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<title>UntitledDocument</title>
<scripttype="text/javascript">
functionchg(){
document.getElementById("setfocus").value="";
}
functionnewChg(){
document.getElementById("setfocus").value="请输入关键字";
}
</script>
</head>
<body>
<inputtype="text"name="name"size="15"class="input"id="setfocus"value="请输入关键字"onfocus="chg()"onblur="newChg()">
</body>
</html>
实例3
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<title>UntitledDocument</title>
<scripttype="text/javascript">
function$(ID){returndocument.getElementById(ID);}
functionchg(){
$("setfocus").value="";
}
functionnewChg(){
if($("setfocus").value==""){
$("setfocus").value="请输入关键字";
}
else{return$("setfocus").value}
}
</script>
</head>
<body>
<inputtype="text"name="name"size="15"class="input"id="setfocus"value="请输入关键字"onfocus="chg()"onblur="newChg()">
</body>
</html>