Home >Web Front-end >JS Tutorial >Javascript dynamically changes the input type attribute

Javascript dynamically changes the input type attribute

高洛峰
高洛峰Original
2016-12-08 11:53:311248browse

Javascript dynamically changes the input type attribute:

Code implementation:

<script type="text/javascript">
  function shoppw(thebox){
    var ps = document.getElementById(&#39;ps&#39;);
    var pass = document.getElementById(&#39;pass&#39;);
    ps.removeChild(pass);
    var psImput = document.createElement("INPUT");
     
    if(pass.type == &#39;password&#39;){
      psImput.type = "text";
    } else {
      psImput.type = &#39;password&#39;;
    }
    psImput.id = &#39;pass&#39;;
    psImput.name = "password";
    psImput.maxlength="15";
    ps.appendChild(psImput);
  }
</script>

HTML code:

<td class="label"> * <label for="password" accesskey="">登录密码:</label></td>
  <td ><div id="ps"><input type="text" name="password" maxlength="15" id="pass" /></div>
   <input name="checkbox2" type="checkbox" value="true" checked="checked" id="show" onclick="shoppw(this)" />
   <label for="show" accesskey="">显示</label></td>

You can dynamically change the type attribute value of the input element at runtime


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