Home  >  Article  >  Web Front-end  >  Discussion on the problem of modifying the type attribute of input in js_javascript skills

Discussion on the problem of modifying the type attribute of input in js_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:20:081049browse

There are some restrictions on modifying the type attribute of input in js. Before the input element is inserted into the document stream, its value can be modified. It is no problem under IE and FF. But if the input already exists on the page, its type attribute becomes a read-only attribute under IE and cannot be modified. It is still a readable and writable attribute under ff.

I encountered a problem today. The input box has a default value of "password", but when it gets focus, the word "password" will be removed, and it will directly change to the password type of "****" when inputting. Obviously, at the beginning, the input type was text, and later it became password type. The intuitive idea is to use js to modify the input type. But this is not feasible under IE, so I can only change my mind and write two inputs, one of text type and one of password type, to monitor onfocus and onblur events respectively. As follows:

Note: The script code must be written into the html

Copy the code The code is as follows:





Adang Production








Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn