我无法弄清楚为什么OnClick事件不会再发生在我的代码中;看到这里的jsfiddle: http://jsfiddle.net/btcAx/2/
HTML:
<input id="LoginID" readonly="readonly" type="password" value="UserName"/>
<br/>
<input id="LoginPW" readonly="readonly" type="password" value="Password"/>
<br/>
<input onclick="change()" type="button" value=" Show/Hide Text " id="ChangeButton"/>
JS:
function change() {
var inp1 = document.querySelector('#LoginID');
var inp2 = document.querySelector('#LoginPW');
if (inp1.type = "password") {
inp1.type = "text";
inp2.type = "text";
}
else {
inp1.type = "password";
inp2.type = "password";
}
}
它会从密码更改为文本类型,但之后它不会改回...
答案 0 :(得分:5)
尝试
if (inp1.type == "password") {
而不是
if (inp1.type = "password") {
答案 1 :(得分:1)
if (inp1.type = "password") {
应该是
if (inp1.type == "password") {