当前位置:网站首页>js和jq实现点击小眼睛后密码显示与隐藏切换
js和jq实现点击小眼睛后密码显示与隐藏切换
2022-08-09 15:03:00 【不知-_】
效果(要求)
眼睛的图标这里是使用了阿里巴巴图标库的图标。
js实现
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>密码框后面的小眼睛</title>
<link rel="stylesheet" href="http://at.alicdn.com/t/font_3448045_gwooawlcz3s.css">
</head>
<body>
<div>
<input type="text" id="pwd">
<i class="iconfont icon-eye-fill" id="eye" onclick="change()"></i>
</div>
<script> var pwd = document.getElementById("pwd"); var eye = document.getElementById("eye"); function change(){
if( pwd.type == "text"){
pwd.type = "password"; eye.class = "iconfont icon-no_eye" } else{
pwd.type = "text"; eye.class = "iconfont icon-eye-fill" } } </script>
</body>
</html>
jq实现
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>密码框后面的小眼睛</title>
<link rel="stylesheet" href="http://at.alicdn.com/t/font_3448045_gwooawlcz3s.css">
<script src="../js/jquery.min.js"></script>
</head>
<body>
<div>
<input type="text" id="pwd">
<i class="iconfont icon-eye-fill" id="eye"></i>
</div>
<script> var pwd = $("#pwd"); var eye = $("#eye"); eye.on('click', function() {
if (pwd.attr("type") == "text") {
pwd.attr("type", "password"); eye.attr("class", "iconfont icon-no_eye"); } else {
pwd.attr("type", "text"); eye.attr("class", "iconfont icon-eye-fill"); } }) </script>
</body>
</html>
一个我的疑问——jq入口函数必须要写吗?
在< head> </ head>标签中,jQuery入口函数必须要写,在< body> </ body>可以不写。
写上入口函数后不论放在哪个标签下都能去执行。一般建议在body标签中写入口函数,就是为了等页面加载完成后才执行入口函数。
边栏推荐
猜你喜欢
随机推荐
easywsclient的DEMO测试
Correlation analysis
webSocket的实现
Unity Shader零基础入门1:纯色物体
缓存层与数据库层数据同步问题
C语言知识细节点(二)
杭州富阳科目三新规3号线考试攻略
Detailed Explanation of Software Secure Memory Area
Unity Shader 透视效果/XRay
灰色关联分析
详解VLAN与划分广播域
RAID磁盘阵列详解
2022.7.18学习总结(Verilog HDL数字集成电路设计原理与应用)
用指针和malloc定义一个数组
Typescript学习(一)
图论最短路径求解
Fiddler抓包夜神模拟器
CTF online encryption and decryption and common tools
Janus介绍
Uart串口学习