jQuery密码的显示与隐藏切换
程序员文章站
2022-07-13 22:06:00
...
<html>
<head>
<meta charset="utf-8">
<title>密码显示与隐藏</title>
</head>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<body>
<div class="fl">
<input type="password" id="pwd" class="text"/>
<input type="checkbox" id="viewpwd"/>
<label>显示密码字符</label>
</div>
<script type="text/javascript">
//设置密码显示和隐藏
$(function () {
$("#viewpwd").change(function () {
/*chekbox选中返回true,否则为false*/
view = $(this).is(":checked");
if (view == true) {
$("#pwd").attr("type", "text");
} else {
$("#pwd").attr("type", "password");
}
})
});
</script>
</body>
</html>