转载地址:http://blog.youkuaiyun.com/siyue_qi/article/details/2472422
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Test </TITLE>
<script>
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)">

<script>


</script>
</BODY>
</HTML>
当鼠标点击文本框时,此时文本框获得焦点,onfocus事件执行,在js里,将文本框隐藏,显示密码框,同时密码框获得焦点。
鼠标离开密码框,如果没有输入密码,则密码框隐藏,文本框显示。
文本框到密码框切换
本文介绍了一种使用JavaScript实现的网页表单中从文本框平滑切换到密码框的方法。当用户点击文本框时,该文本框会隐藏并显示密码框供用户输入密码;若用户未输入密码并移出密码框,文本框则重新出现。

被折叠的 条评论
为什么被折叠?



