如何在JQuery中将输入文本字段交换到焦点上的密码区域? [英] How can you swap an input text field to a password area on focus in JQuery?
问题描述
我想在密码区域中显示密码作为文本,当关注时,该框应该变为空,并允许来自用户的正常密码(加星标)输入。
I would like to display "password" as text in the password area, and when focused the box should become empty and allow normal password (starred out) input from the user.
目前我使用以下方法。最初,我会显示一个显示密码的文本字段,当它被移除并替换为密码字段时。这里是jQuery:
Currently I use the following method. Initially I display a text field showing password, when focused it is removed and replaced with a password field. Here is the jQuery:
$(document).ready(function() {
$("#password").focus( function() {
$("#pwd").html('<input type="password" id="password" name="password" value="" />');
$("#password").focus();
});
});
这适用于Firefox和Chrome,但在IE 8(大概是其他IE)由于某种原因失败(也许DOM尚未准备好?)。
This works on Firefox and Chrome but fails in IE 8 (and presumably other IE's) as the focus call fails for some reason (maybe the DOM isn't ready?).
演示可在 jsbin 。
有什么想法?
Any ideas?
推荐答案
您可以尝试水印插件。我不知道它在IE8中是否有效。
You could try the watermarker plugin. I don't know if it works in IE8.
这篇关于如何在JQuery中将输入文本字段交换到焦点上的密码区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!