複選框選中的時候顯示密碼password改爲text

糾結了半天,就爲了實現把密碼顯示出來,而不是用*號代替

我們一般用的<input type="password" id="account_pwd" name="account_pwd" value="<%=account.getAccount_pwd()%>" />默認顯示出來的是*****號代替的,在後面加個複選框,當複選框被選中的時候讓密碼顯示出來,也就是password改爲text


很容易進入一個錯誤的思想,就是想着去獲取這個標籤,然後改變它的類型type="text"

要是這樣想的話你就打錯特錯了【(*^__^*) 嘻嘻,我之前就是這麼想的、o(︶︿︶)o 唉、笨】


type屬性在jsp裏面是隻讀的,你根本不能改變type的值,但是在一般的html中可以使用type=“text”來實現效果


說了這麼多來看看我是怎麼實現的【哈哈,有點囉嗦】

html:


<input type="hidden"  name="value" value="<%=account.getAccount_pwd()%>" />
<span id="pwdTd" style="width: 100px;">
<input type="password" id="account_pwd" name="account_pwd" value="<%=account.getAccount_pwd()%>" />
</span>
<input type="checkbox" id="show" οnclick="showPwd()"/>顯示密碼



js:

function showPwd(){
var show=document.getElementById("show");
var value=document.getElementById("value").value;//獲取隱藏表單域中存儲的從數據庫中讀取出來的值
if(show.checked==true){
document.getElementById("pwdTd").innerHTML="<input type='text' id='account_pwd' name='account_pwd' value='"+value+"' />";
}else{
document.getElementById("pwdTd").innerHTML="<input type='password' id='account_pwd' name='account_pwd' value='"+value+"' />";
}
}

發佈了41 篇原創文章 · 獲贊 12 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章