【发布时间】:2017-09-09 11:58:54
【问题描述】:
我一直在从事一个项目,该项目要求我在表单密码字段上实现一个显示/隐藏按钮,该按钮在将密码显示为纯文本和将其隐藏在星号后面之间切换。
到目前为止我想出了什么:
function pass(){ document.getElementById('password').type="password"; }
function text(){ document.getElementById('password').type="text"; }
<input type="password" id="password" />
<button class="ui-component__password-field__show-hide" type="button" onclick="text()">Show</button>
它可以很好地切换到显示密码,但是如何使它在显示密码后将按钮的文本更改为“隐藏”,并使其执行 pass() 函数?
【问题讨论】:
标签: javascript passwords field hide show