JavaScript 文本框变成密码框

来源:互联网 发布:清单好帮手软件 编辑:程序博客网 时间:2024/04/26 15:59
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE>Test</TITLE><script type="text/javascript">function show(obj){if(obj.type=="text"){obj.style.display = "none";document.getElementById('pass').style.display = "block";document.getElementById('pass').value="";document.getElementById('pass').focus();}else{var pass = document.getElementById('pass').value;if(pass.length<1){obj.style.display = "none";document.getElementById('txt').style.display = "block";}}}</script></HEAD><BODY><input id="txt" type="text" value="请输入密码" onfocus="show(this)" style="width:150px;height:20px"><input id="pass" type="password" value="" style="display:none;width:150px;height:20px" onblur="show(this)"></BODY></HTML>