Отображение предопределенного ***** в asp.net TextBox когда TextMode = "Пароль" - PullRequest
0 голосов
/ 29 октября 2011

TextBox с TextMode = "Password" будет пустым после присвоения значения его текстовому свойству.

Как я могу установить предопределенный пароль для моего текстового поля пароля?

Также я хочу использовать этот код jQuery для моего текстового поля:

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

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

1 Ответ

1 голос
/ 29 октября 2011

Вы можете сделать это следующим образом .... используя jquery .....

, используя функцию ниже, мы можем показать и скрыть два разных ввода.Вам нужно установить один с идентификатором Password, а другой с идентификатором 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’);
}});
}
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...