我需要在点击眼睛图标时显示和隐藏用户密码,因此我编写了脚本。但是,当我点击眼睛图标时,只有类改变了,但密码没有显示;再次点击斜杠-眼睛图标时,应该隐藏这两种方法都不起作用,如何解决这个问题?
<input type="password" name="player_password" id="pass_log_id" />
<span toggle="#password-field" class="fa fa-fw fa-eye field_icon toggle-password"></span>
<script>
$("body").on('click','.toggle-password',function(){
$(this).toggleClass("fa-eye fa-eye-slash");
var input = $("#pass_log_id").attr("type");
if (input.attr("type") === "password") {
input.attr("type", "text");
} else {
input.attr("type", "password");
}
});
</script>