我想在我的密碼字段中顯示「密碼」的水印。
這裏是我的代碼:
的jQuery:如何將密碼字段中的文字水印?
$(document).ready(function() {
var watermark = 'Password';
//init, set watermark text and class
$('#input_pwd').val(watermark).addClass('watermark');
//if blur and no value inside, set watermark text and class again.
$('#input_pwd').blur(function(){
if ($(this).val().length == 0){
$(this).val(watermark).addClass('watermark');
}
});
//if focus and text is watermrk, set it to empty and remove the watermark class
$('#input_pwd').focus(function(){
if ($(this).val() == watermark){
$(this).val('').removeClass('watermark');
}
});
});
HTML:
<input class="ui_input" id="input_pwd" type="password" name="pass" id="pass" style="height:25px; width:250px; font-size:14px;" required />
我的jsfiddle: click here
編輯:我喜歡jQuery的:)
編輯:我們的兄弟Konrad Gadzina給了我我正在尋找的東西,但是感謝所有人的努力!
你的意思是 「佔位符」? – Raptor 2013-04-26 10:00:23
https://github.com/Topener/jQuery-html5-placeholder – 2013-04-26 10:01:19
在您進一步學習之前,請先了解水印和佔位符的定義 - 它們甚至幾乎沒有關係。 – George 2013-04-26 10:02:44