Change TextBox TextMode with jQuery
I was wondering if someone knew the best way to switch from using the
myTextBox.TextMode = TextBoxMode.Password;
to
myTextBox.TextMode = TextBoxMode.Si开发者_C百科ngleLine;
using client code and jQuery. I will have to do it on focus, along with deleting the whole text content of the textbox onFocus event.
$('#idOfYourTextbox').attr('type', 'text');
However, you cannot change the type of type="password"
fields in IE (yay for useless "security" features).
These webcontrols render completly different: the TextBox with mode SingleLine renders as an an input element with type=text, TextMode.Password changes the rendering to an input element with type=password.
So although in asp.net it is a single property, in jquery you will have to change the attribute type:
$('input.someclass').attr('type','password');
There are however some security limitations. See also this question.
If you also would like to change to TextMode.Multiline, you will have to change the input element to a textarea element.
I don't think you can. Best thing to do is have two text boxes and then hide one on focus and show the other then focus it manually.
$('input:password').focus(function() {
$(this).hide();
$(this).siblings('input:text').show().focus();
});
This assumes they are both in the same container and the text box is hidden to start with.
精彩评论