我有一個顯示/隱藏密碼按鈕,當我單擊以顯示密碼時,它的工作原理,但是當我嘗試再次隱藏它時,它不會。更改元素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