这篇文章主要介绍了javascript 动态改变imput type属性的相关资料,并附简单实例代码,需要的朋友可以参考下
javascript 动态改变imput type属性:
代码实现:
<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代码:
<td class="label"> * <label for="password" accesskey="">登录密码:</label></td>
<td ><p id="ps"><input type="text" name="password" maxlength="15" id="pass" /></p>
<input name="checkbox2" type="checkbox" value="true" checked="checked" id="show" onclick="shoppw(this)" />
<label for="show" accesskey="">显示</label></td>
可以运行时动态改变imput元素的type属性值
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
js用事件委托给元素增加事件
js里new()使用技巧
js易错点总结与解决
以上就是利用js实现动态改变imput type属性的详细内容。