<style>
* {
margin: 0;
padding: 0;
}
#box {
width: 200px;
height: 30px;
border: 1px solid;
}
</style>
</head>
<body>
<input type="password" id="box">
<button id="btn">显示/隐藏</button>
</input>
<script>
/* 获取 */
var btn = document.getElementById('btn')
var box = document.getElementById('box')
/* */
var flag = 0;
/* 添加点击事件 */
btn.onclick = function() {
if (flag == 0) {
box.type = 'text'
flag = 1
} else {
box.type = 'password'
flag = 0
}
}
</script>
</body>