你可以做這樣的....使用jQuery .....
並隱藏兩個不同的輸入。您需要使用ID Password和ID PasswordDummy設置一個,對於沒有javascript的客戶,最好設置PasswordDummy以顯示:最初沒有。
$(‘input’).each(function()
{
if (this.id == ‘Password’) {
// Handle Password differently – it only gets an onblur, in which it gies invisible and activates the PasswordDummy if it is empty
// if its blank, make it invisible and Dummy visible
if (this.value == 」)
{
$(this).hide();
$(「#PasswordDummy」).show();
}
else
{
$(this).show();
$(「#PasswordDummy」).hide();
}
$(this).blur(function()
{
if (this.value == 」) {
$(this).hide();
$(「#PasswordDummy」).show();
}
else
{
$(this).show();
$(「#PasswordDummy」).hide();
}
});
}
else if (this.id == ‘PasswordDummy’) {
// Handle Password Dummy differently
this.value = $(this).attr(‘title’);
$(this).addClass(‘text-label’);
$(this).focus(function()
{
$(this).hide();
$(「#Password」).show();
$(「#Password」).focus(); });
}
else if ($(this).attr(‘title’) != undefined)
{
if (this.value == 」)
{
this.value = $(this).attr(‘title’);
$(this).addClass(‘text-label’);
}
$(this).focus(function()
{
if (this.value == $(this).attr(‘title’)) {
this.value = 」;
$(this).removeClass(‘text-label’);
}});
$(this).blur(function()
{
if (this.value == 」) {
this.value = $(this).attr(‘title’);
$(this).addClass(‘text-label’);
}});
}
});
我沒有-1,但我沒有標誌作爲複製OF- http://stackoverflow.com/questions/4797166/set-default-value-of-a-password-input-so-it -can-be-read – davidsleeps