更改 input type 的值

2021-09-08 22:23:54 字數 912 閱讀 6247

需要實現的效果:乙個輸入框,當輸入框未獲得焦點的時候,value 值為 「密碼」;當輸入框失去焦點的時候,輸入內容顯示為」*****」

我們很直接會想到下面的js

$(「#showpwd」).focus(function());

發現並沒有實現預期效果,出現 uncaught exception type property can't be changed 錯誤,檢視jquery 1.42原始碼 1488 行

// we can't allow the type property to be changed (since it causes problems in ie)

if ( name === 「type」 && rtype.test( elem.nodename ) && elem.parentnode )

jquery 修改不了用源生的js呢?

$(「#pwd」).focus(function());

發現在ff下可以修改並將密碼輸入框type 修改為 「password」 並將 value設定為空,而ie下卻提示無法得到type屬性,不支援該命令。 彈出 type 看看真的無法得到嗎?

$(「#showpwd」).focus(function());

發現彈出text ,原來不是無法得到,只是ie下不能修改。 因此,我們想到可以先remove然後再生成乙個type是password的密碼輸入框。

下面type為password的輸入框

$(「#showpwd」).focus(function()

});$(「#password」).blur(function()

});最終效果: 當輸入框獲得焦點的時,輸入的內容顯示為「****」;當失去焦點的時,內容為空時顯示「密碼」。

editText中inputtype的使用屬性

文字型別,多為大寫 小寫和數字符號。android inputtype none 輸入普通字元 android inputtype text 輸入普通字元 android inputtype textcapcharacters 輸入普通字元 android inputtype textcapword...

Editext的inputType常用屬性

多行輸入,回車鍵為換行,無其他功能 inputtype填入屬性後,預設singleline true 效果,這裡除外 text 普通 textpassword 不可見密碼 textcapcharacters 字母大寫 textcapwords 首字母大寫 textcapsentences 僅第乙個字...

input type型別與定義的寬高

近來,在寫input表單時候,忽然發現乙個問題,那就是 雖然input可以設定寬高,在設定width和height相同時,當type型別不同,其對應的寬高效果也完全不一致,先上 lang en charset utf 8 testtitle type text css rel stylesheet ...