我有一个显示/隐藏密码按钮,当我单击以显示密码时,它的工作原理,但是当我尝试再次隐藏它时,它不会。更改元素ID后无法触发操作
小提琴:http://jsfiddle.net/vcvgj09z/
<input type="password" id="pass1" value="Now try to hide me">
<a href="#" id="show-password"><i class="fa fa-eye"></i> Show</a>
$("#show-password").on("click",function() {
$(this).html('<i class="fa fa-eye-slash"></i> Hide');
$(this).prop("id","hide-password");
$("#pass1").attr("type","text");
});
$("#hide-password").on("click",function() {
$(this).html('<i class="fa fa-eye"></i> Show');
$(this).prop("id","show-password");
$("#pass1").attr("type","password");
});
不要更改元素的ID ... – 2014-12-05 17:08:21
试图删除/ addClass太:( – 2014-12-05 17:08:44
在你的代码中的点击事件时运行的约束 - 和在运行时'#hide-password'不存在 – Terry 2014-12-05 17:08:59