JS鼠标点击密码框提示文字就消失,鼠标移出密码框提示文字就再出现怎么做?不是文本框,而是密码框。

像新浪微博那样的登陆框

我以前用的一个方法
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("input[type=text]").focus(function () {
$(this).hide();
$("input[type=password]").show().focus();
})
$("input[type=password]").blur(function () {
if ($(this).val()=="") {
$(this).hide();
$("input[type=text]").show();
}
})
});
</script>
</head>
<body>
<div>
<input type="text" value="请输入密码" style="width:150px; height:20px;"/><input type="password" style="width:150px; height:20px;display: none;" /></div>
</body>
</html>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-07-27
现代浏览器 支持 placeholder 属性 即可实现你要的效果 ie浏览器不支持
例如
<input type="text" placeholder="请输入密码" />
第2个回答  2012-07-27
<input type="text" value="please input password" onfocus="psw(this)" onblur="txt(this)"/>

function psw(el) {
if (el.value == 'please input password') {
el.value = '';
el.type = 'password';
}
}
function txt(el) {
if (!el.value) {
el.type = 'text';
el.value = 'please input password';
}
}本回答被网友采纳
相似回答