最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - this.type='password' doesn't work in IE, but all other browsers it does - Stack Overflow

programmeradmin7浏览0评论

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?

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?

Share Improve this question asked Aug 22, 2009 at 14:45 James SimpsonJames Simpson 13.7k26 gold badges85 silver badges111 bronze badges 3
  • That's why advise against never using I.E again. – jay_t55 Commented Aug 22, 2009 at 15:28
  • yeah, great thought but 60% of your users have other ideas...! – redsquare Commented Aug 22, 2009 at 15:33
  • Yeah, true! :-) I don't mind developing for Internet Explorer, although I do wish it was easier lol. – jay_t55 Commented Aug 22, 2009 at 15:53
Add a ment  | 

3 Answers 3

Reset to default 6

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./articles/makingpactformsmoreaccessible/

发布评论

评论列表(0)

  1. 暂无评论