how to change textbox textmode using jquery
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.
精彩评论