html显示密码的代码是什么,单击显示密码.html

本文介绍了一个简单的网页设计技巧,通过点击图片实现输入框类型(文本到密码)的快速切换,提升用户体验。使用了JavaScript事件处理来控制输入框类型和图片显示状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Document

.box {

width: 400px;

border-bottom: 1px solid #ccc;

margin: 100px auto;

position: relative;

}

.box input {

width: 370px;

height: 30px;

border: 0;

outline: none;

}

.box img {

position: absolute;

width: 24px;

top: 2px;

right: 2px;

}

// 获取元素

var img = document.querySelector("img");

var input = document.querySelector("input");

// 绑定事件,处理程序 处理按钮多次点击的事件

var flag = 0;

img.onclick =function(){

if(flag==0){

input.type = 'text';

this.src = 'images/open.png';

flag = 1;

}else{

input.type = 'password';

this.src = 'images/closed.png';

flag = 0;

}

}

一键复制

编辑

Web IDE

原始数据

按行查看

历史

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值