鼠標按下時,密碼銘文顯示,鼠標擡起時,密碼銘文不顯示
blade模板
這裏使用了bootstrap 的icon font
<input type="password" value="{{ old('password') }}" >
<i onmouseup="Pwdtag(this,false)" onmousedown="Pwdtag(this,true)" class="glyphicon glyphicon-eye-close"></i>
js部分
操作i標籤的上一個元素prev(),也即input標籤的type屬性
function Pwdtag (obj,flag) {
if (flag) {
$(obj).removeClass('glyphicon-eye-close').addClass('glyphicon-eye-open')
$(obj).prev().attr('type','text')
} else {
$(obj).removeClass('glyphicon-eye-open').addClass('glyphicon-eye-close')
$(obj).prev().attr('type','password')
}
}