this.type='密码'在 IE 中不起作用,但在所有其他浏览器中都可以

发布于 2024-08-02 09:33:27 字数 197 浏览 7 评论 0原文

我有一个输入字段,默认设置为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜宝宝 2024-08-09 09:33:27

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.

飞烟轻若梦 2024-08-09 09:33:27

你想达到什么效果?您是否希望初始密码可见,但当他们输入新密码时,它会被隐藏?如果是这样,您可能只想用密码输入替换该元素,并复制该值。

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.

允世 2024-08-09 09:33:27

你最好使用

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文