Home >Web Front-end >HTML Tutorial >Modify the type attribute of the input box_html/css_WEB-ITnose

Modify the type attribute of the input box_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:12:05994browse

<ul class="login_list"  id="web_login">                <li class="login_input">                    <input id="u" name="u"  tabindex="2" class="input_txt" type="text" value="User name" onFocus="this.value=''" onBlur="if(!value){value=defaultValue;}" />                </li>                <li class="login_input">                    <input type="text" class="input_txt2" value="Password" onfocus="if(this.value==defaultValue) {this.value='';this.type='password'}" onblur="if(!value) {value=defaultValue; this.type='text';}" />                </li></ul>


I want to make the input boxes blank when the mouse focus is on the two input boxes, but there is a problem when clearing the password. The password entered by the user should be " *****", it does not work under IE8, please help me solve it, thank you


Reply to the discussion (solution)

type is a read-only attribute and cannot be modified.
This is the only way

<script type="text/javascript"> function changeType(obj) {     obj.style.display = "none";     document.getElementById("d2").style.display = "";     document.getElementById("d2").focus(); } </script>

<ul class="login_list"  id="web_login">    <li class="login_input">        <input id="u" name="u"  tabindex="2" class="input_txt" type="text" value="User name" onFocus="this.value=''" onBlur="if(!value){value=defaultValue;}" />    </li>    <li class="login_input">        <input type="text" class="input_txt2" value="Password" onfocus="changeType(this)" onblur="if(!value) {value=defaultValue; this.type='text';}" />	<input type="password" class="input_txt2" id="d2" value="" style="display:none" />     </li></ul>

How can I modify the read-only attribute?

The password box must use type="password"

Refresh·························· ··················

type is a read-only attribute and cannot be modified.
That’s all.
JScript code

4ec11beb6c39d0703d1751d203c17053
function changeType(obj) {
obj.style.display = "none ";
document.getElementById("d2").style.display = "";
docum...

I have found the solution, it is the same as the original poster, I learned it, thank you

<input name="" type="text" value="Password" class="inputText_1" id="tx"  /><input name="" type="password" style="display:none;" id="pwd" class="inputText_1" />


<script type="text/javascript">var tx = document.getElementById("tx"), pwd = document.getElementById("pwd");tx.onfocus = function(){if(this.value != "Password") return;this.style.display = "none";pwd.style.display = "";pwd.value = "";pwd.focus();}pwd.onblur = function(){if(this.value != "") return;this.style.display = "none";tx.style.display = "";tx.value = "Password";}</script>


Friends who have encountered similar problems can refer to it

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