2011-10-29 31 views
-1

將TextMode =「密碼」的TextBox在爲其文本屬性賦值後將爲空。當文本模式=「密碼」時,在asp.net TextBox中顯示預定義的*****

如何爲我的密碼文本框設置預定義的密碼?

此外,我想用這個jQuery代碼爲我的文本框:用以下函數就可以顯示

function onclickOfPassword(This) { 
    if (This.value == 'Password') { 
     This.value = ''; 
    } 
} 

function onblurOfPassword(This) { 
    if (This.value == '') { 
     This.value = 'Password'; 
    } 
} 
+0

我沒有-1,但我沒有標誌作爲複製OF- http://stackoverflow.com/questions/4797166/set-default-value-of-a-password-input-so-it -can-be-read – davidsleeps

回答

1

你可以做這樣的....使用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’); 
}}); 
} 
}); 
+0

如果你縮進你的代碼,會很好:) – Kev

相關問題