亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

js修改input的type屬性及瀏覽器兼容問題探討與解決

 更新時(shí)間:2013年01月23日 14:26:35   投稿:whsnow  
js修改input的type屬性有些限制,今天遇到個問題一開始的時(shí)候,input的類型是text,后來變成了password類型。直觀的思路是用js修改input的type類型。但ie下這么做不可行,所以只能換個思路感興趣的朋友可以了解下

js修改input的type屬性有些限制。當(dāng)input元素文檔流之前,是可以修改它的值的,在ie和ff下都沒問題。但如果input已經(jīng)存在于頁面,其type屬性在ie下就成了只讀屬性了,不可以修改。在ff下仍是可讀寫屬性。

今天遇到個問題,輸入框有默認(rèn)值“密碼”,但獲得焦點(diǎn)時(shí),“密碼”兩字會去掉,輸入時(shí)直接變成”****“的password類型。很明顯,一開始的時(shí)候,input的類型是text,后來變成了password類型。直觀的思路是用js修改input的type類型。但ie下這么做不可行,所以只能換個思路,寫兩個input,一個text類型,一個password類型,分得onfocus和onblur事件。如下:

復(fù)制代碼 代碼如下:

<!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>錢運(yùn)來|qianyunlai.com制作</title>
</head>
<style type="text/css">
</style>
<body>
<input name="" type="text" value="密碼" 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.value = "";
pwd.focus();
}
pwd.onblur = function () {
if (this.value != "")
return;
this.style.display = "none";
tx.style.display = "";
tx.value = "密碼";
}
</script>
</body>
</html>

相關(guān)文章

最新評論