Heim >Web-Frontend >js-Tutorial >Javascript ändert das Eingabetypattribut dynamisch
Javascript ändert dynamisch das Eingabetypattribut:
Code-Implementierung:
<script type="text/javascript"> function shoppw(thebox){ var ps = document.getElementById('ps'); var pass = document.getElementById('pass'); ps.removeChild(pass); var psImput = document.createElement("INPUT"); if(pass.type == 'password'){ psImput.type = "text"; } else { psImput.type = 'password'; } psImput.id = 'pass'; 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>
Sie können den Typattributwert des Eingabeelements zur Laufzeit dynamisch ändern