2015-10-26 62 views
0

我有簡單的形式至極包含密碼字段:輸入HTML/JS顯示密碼後,模糊/對焦

<input required type="password" value="Insert password" style="color:#888;" onfocus="inputFocus(this)" onblur="inputBlur(this)"> 

JS功能(點擊後明確和變色..):

function inputFocus(input) { 
    if (input.value === input.defaultValue) { 
     input.value = ""; 
     input.style.color = "#000"; 
    } 
} 
function inputBlur(input) { 
    if (input.value === "") { 
     input.value = input.defaultValue; 
     input.style.color = "#888"; 
    } 
} 

如果我加載頁面,我希望在輸入欄中看到標準值。對於類型type="text"這不是問題,但對於type="password"我只看到點。 我想看到默認值(插入密碼),但是當用戶開始輸入密碼時,他必須看到點。

怎麼樣?

謝謝您的回覆。

+1

你有沒有意識到瀏覽器有這個內置的?佔位符屬性。 – epascarello

+0

如果你想向用戶顯示他們輸入的密碼,你可以使用attr(「type」,「text」);或attr(「type」,「password」);但對於佔位符,您應該使用以上建議 – Puzzle84

回答

2

使用佔位符屬性:

<input required type="password" placeholder="Insert password" />

0

怎麼樣的HTML5佔位?你並不需要的JavaScript這樣的:

<input required type="password" placeholder="Insert password" style="color:#888;">