【问题标题】:Display predefined ***** in asp.net TextBox when TextMode = "Password"当TextMode =“Password”时在asp.net TextBox中显示预定义的*****
【发布时间】:2011-12-17 19:20:15
【问题描述】:

TextMode = "Password" 的 TextBox 在为其 text 属性赋值后将为空。

如何为我的密码文本框设置预定义密码?

我也想为我的文本框使用这个 jQuery 代码:

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

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

【问题讨论】:

标签: c# asp.net textbox passwords


【解决方案1】:

你可以这样做......使用 jquery .....

通过使用下面的函数,我们可以显示和隐藏两个不同的输入。您需要设置一个 ID 密码和另一个 ID PasswordDummy,对于没有 javascript 的客户端,最好将 PasswordDummy 初始设置为 display:none。

$(‘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’);
}});
}
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-06
    • 2020-01-12
    • 1970-01-01
    • 2011-05-01
    • 2017-11-21
    • 1970-01-01
    • 2012-07-18
    • 2014-01-07
    相关资源
    最近更新 更多