简体   繁体   English

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

[英]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.

相关问题 简单的Javascript在FireFox中不起作用(但在所有其他浏览器中都有效) - Simple Javascript doesn't work in FireFox (but does in ALL other Browsers) 复选框输入在chrome中根本不起作用。 在其他浏览器中不起作用 - Checkbox Input doesn't work at all in chrome. Doesn't function in other browsers Javascript代码不适用于IE11,但适用于所有其他浏览器 - Javascript code does not work on IE11, but works on all other browsers 更改背景并非在所有浏览器中都有效 - Changing background doesn't work in all browsers focus()在输入中不起作用(所有浏览器) - focus() doesn't work in input (all browsers) 绘制LineChart时IE8崩溃—所有其他浏览器均正常工作 - IE8 Crashes When Drawing LineChart — All Other Browsers Work 有没有办法在IE中阻止我的网站,让它在所有其他浏览器中工作 - Is there a way to block my website in IE and let it work in all other browsers 我的Javascript代码在IE中不起作用,但在其他浏览器中也可以正常工作 - My Javascript code does not work in IE but works fine in other browsers 为什么此javascript在IE中不起作用,而在其他浏览器中起作用? - Why does this javascript not work in IE but works in other browsers? XMLHttpRequest在IE 7/8中不起作用,但在其他浏览器中起作用 - XMLHttpRequest won't work in IE 7/8 but works in other browsers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM