第1个回答 2014-09-16
<input type="text" id="pwd" />
<input type="hidden" id="pwdvalue" />
<script type="text/javascript">
var pwd = document.getElementById("pwd");
var pwdvalue = document.getElementById("pwdvalue");
pwd.onkeypress = function() {
var code = arguments[0].keyCode
pwdvalue.value += String.fromCharCode(code);
arguments[0].returnValue = false;
pwd.value += "x";
}
</script>
第2个回答 推荐于2017-09-29
<input type="text" id="pwds" />
$("input#pwds").on('blur', function(){
var obj = $(this);
obj.attr('type', 'text').val('密码');
}).on('focus', function(){
var obj = $(this);
obj.attr('type', 'password').val('');
});本回答被提问者采纳
第3个回答 2014-09-16
只要在密码框的input 获得焦点时触发,当获得焦点时,控制value的同时,改变type属性,把type属性置为password 应该就行了,
第4个回答 2014-09-16
仅供参考
<html>
<head>
<script src="./jquery-1.9.1/jquery-1.9.1.min.js"></script>
<script>
$(function() {
var pwd = $("#pwd");
pwd.attr("type","text");
pwd.bind("focus",function() {
pwd.attr("type","password");
pwd.attr("value","");
});
pwd.bind("blur",function() {
var pwdtext = pwd.val();
if(pwdtext.length === 0){
pwd.attr("type","text");
pwd.attr("value","密码");
}
});
});
</script>
</head>
<body>
<form>
<input id="pwd" type="password" value="密码">登录
</form>
</body>
</html>