<!
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 >
< 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里,将文本框隐藏,显示密码框,同时密码框获得焦点。
鼠标离开密码框,如果没有输入密码,则密码框隐藏,文本框显示。