首页 > 代码库 > js修改input的type属性问题(兼容所有浏览器,主要用于密码类的默认有提示文字的效果)

js修改input的type属性问题(兼容所有浏览器,主要用于密码类的默认有提示文字的效果)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>阿当制作</title>
</head>
<style type="text/css">

</style>
<body>
<input name="" type="text" value="http://www.mamicode.com/密码" class="inputText_1" id="tx" style="width:100px;"  />
<input name="" type="password" style="display:none;width:100px;" id="pwd" />
<script type="text/javascript">
var tx = document.getElementById("tx"), pwd = document.getElementById("pwd");
tx.onfocus = function(){
if(this.value != "密码") return;
this.style.display = "none";
pwd.style.display = "";
pwd.valuehttp://www.mamicode.com/= "";
pwd.focus();
}
pwd.onblur = function(){
if(this.value != "") return;
this.style.display = "none";
tx.style.display = "";
tx.valuehttp://www.mamicode.com/= "密码";
}
</script>
</body>
</html>

js修改input的type属性问题(兼容所有浏览器,主要用于密码类的默认有提示文字的效果)