button {
background-color: pink;
border-radius: 10px;
}
input {
border-radius: 10px;
height: 20px;
}
<input type="password">
<button>显示密码</button>
// 获取元素
var inpu = document.querySelector('input') // 获取input框
var butt = document.querySelector('button') // 点击按钮
// 设置点击事件
butt.onclick = function () {
// console.log(123)
// 获取type属性
var i = inpu.type
// console.log(i) // 运行结果:password
// if判断
// if(i === 'password'){
// inpu.type = 'text'
// } else {
// inpu.type = 'password'
input密码可见切换
最新推荐文章于 2025-06-10 10:44:35 发布