Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 17:20:08
Original
1050 people have browsed it

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








Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template