开发者

how to change textbox textmode using jquery

开发者 https://www.devze.com 2023-03-03 08:28 出处:网络
i have a login component and within it the passwo开发者_开发问答rd field has a textmode of singlline

i have a login component and within it the passwo开发者_开发问答rd field has a textmode of singlline

what i am trying to do is on focus the textmode will change to password

i tried this :

$(function () {
   $(".PassTextBox").focus(function (pas) {
       $(".PassTextBox").attr("TextMode", "Password");
   });
});

but it didn't work

using asp.net 3.5 , thanks


Why not display it as a password field from the start ?

If you have to, take a look at How display text in password field

It is not as simple as it seems because IE (before v9) does not allow to dynamically change the type of the textbox, so you will have to actually replace it with another one.


You'll need to change the "type" attribute to password. "TextMode" is an asp.net control attribute, but on the client side it gets turned into an HTML input, which has a type attribute: http://htmlhelp.com/reference/html40/forms/input.html

$(function () {
$(".PassTextBox").focus(function (pas) {
    $(".PassTextBox").attr("Type", "Password");
});
});

UPDATE: After testing this to confirm it works, it appears changing the type may not be supported on all browsers or by jQuery. This answer will give you some more insight. My suggestion is to put two fields on the form and dynamically show/hide them to give the same effect.


Do this:

$(function () {
  $(".PassTextBox").focus(function (pas) {
    $(".PassTextBox").attr("type", "password");
  });
});

Hope this works.

0

精彩评论

暂无评论...
验证码 换一张
取 消