[英]this.type='password' doesn't work in IE, but all other browsers it does
I have an input field that is by default set to type="text" so that the word Password can be displayed in it. 我有一个输入字段,默认情况下设置为type =“text”,以便可以在其中显示密码一词。 I have the following to change it to a password field when the user selects it, which works fine in any browser I have tried except Internet Explorer.
当用户选择密码字段时,我有以下内容将其更改为密码字段,这在我尝试过的除Internet Explorer之外的任何浏览器中都能正常工作。
onfocus="this.type='password';"
How would I go about making this work in IE? 我将如何在IE中完成这项工作?
IE does not like to change the type of an element dynamically, one solution might be to replace the element entirely. IE不喜欢动态地改变元素的类型,一种解决方案可能是完全替换元素。 However I would suggest you just use a input type password so any non js users would still get the same functionality and live without the watermark.
但是我建议你只使用一个输入类型的密码,这样任何非js用户仍然可以获得相同的功能,并且没有水印。
What effect are you trying to achieve? 你想要达到什么效果? Do you want the initial password to be visible, but when they go to enter a new one, it's obscured?
您是否希望初始密码可见,但是当他们进入新密码时,它会被隐藏? If so, you might want to simply replace the element with a password input, copying the value.
如果是这样,您可能只想用密码输入替换元素,复制该值。
You are better off using a <label> with the text "password" rather than displaying it inside the control itself. 最好使用带有文本“password”的<label>,而不是在控件本身内显示它。 You can make the label appear like it is inside the textbox using css.
您可以使用css使标签看起来像在文本框内。 A List Apart has a good article on this sort of thing: http://www.alistapart.com/articles/makingcompactformsmoreaccessible/
List Apart有一篇关于此类事情的好文章: http : //www.alistapart.com/articles/makingcompactformsmoreaccessible/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.