当前位置:网站首页>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标签中写入口函数,就是为了等页面加载完成后才执行入口函数。
边栏推荐
猜你喜欢
【QT】QLayout: Attempting to add QLayout “to ***“, which already has a layout的终极解决方法
WinServer 2019 组策略开启远程桌面
安装MySQL时出现starting the server失败
qemu虚拟机模拟固件环境搭建
如何通过Photoshop根据纹理贴图轻松获得法线贴图
vmware workstation 未能启动vmware
初学ARM的个人心得
软件测试流程
服务端媒体引擎框架
Heap series_0x08: NT heap debug support_Discover now debug support (DPH)
随机推荐
软件测试工具清单
Unity Shader零基础入门2:环境光、漫反射、高光
Ntdsutil 转移主域控五大角色
CTF online encryption and decryption and common tools
Unity Shader零基础入门4:纹理贴图与法线贴图
Unity Shader 透视效果/XRay
文件IO及其函数使用
Dolphin Scheduler 2.x版本部署篇
Heap series _0x02: The past and present of the heap (WinDbg+Visual Studio compilation)
QT页面跳转的实现
RTP协议封装音视频媒体数据详解
TOPSIS优劣解距离法
Detailed Explanation of Software Secure Memory Area
服务端媒体引擎框架
【QT】QLayout: Attempting to add QLayout “to ***“, which already has a layout的终极解决方法
杭州富阳科目三新规3号线考试攻略
PhotoshopCS6视频教程学习笔记-基础部分之一
wireshark抓包新手使用教程
层次分析法
路由概述与静态配置ip