this.type='密码'在 IE 中不起作用,但在所有其他浏览器中都可以
我有一个输入字段,默认设置为 type="text",以便可以在其中显示“密码”一词。当用户选择它时,我可以将其更改为密码字段,这在我尝试过的任何浏览器(Internet Explorer 除外)中都可以正常工作。
onfocus="this.type='password';"
我该如何在 IE 中实现此功能?
I have an input field that is by default set to type="text" so that the word Password can be displayed in it. 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.
onfocus="this.type='password';"
How would I go about making this work in IE?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
IE 不喜欢动态更改元素的类型,一种解决方案可能是完全替换该元素。不过,我建议您只使用输入类型密码,这样任何非 js 用户仍然可以获得相同的功能并且没有水印。
IE does not like to change the type of an element dynamically, one solution might be to replace the element entirely. 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.
你想达到什么效果?您是否希望初始密码可见,但当他们输入新密码时,它会被隐藏?如果是这样,您可能只想用密码输入替换该元素,并复制该值。
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. You can make the label appear like it is inside the textbox using css. A List Apart has a good article on this sort of thing: http://www.alistapart.com/articles/makingcompactformsmoreaccessible/