网站首页 > 技术文章 正文
示例简介
利用JQ模拟六位密码支付效果,效果如下图:
实现过程
功能比较简单,代码如下,主要功能都有注释:
body {
margin: 0;
padding: 0;
background-color: #c7c8ca;
}
.pop-box {
display: none;
}
.pop-box .mask {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
z-index: 1;
}
.pwd-wrapper {
background-color: #fff;
position: absolute;
top: 50%;
left: 50%;
z-index: 2;
width: 280px;
height: 160px;
margin-left: -140px;
margin-top: -80px;
border-radius: 7px;
}
.pwd-top {
padding: 25px 0 35px;
}
.pwd-top .title {
text-align: center;
color: #333;
font-size: 16px;
}
.pwd-top img {
width: 15px;
height: 15px;
position: absolute;
top: 14px;
right: 14px;
}
.pwd-box {
width: 224px;
position: relative;
border: 1px solid #E5E5E5;
overflow: hidden;
margin: 0 auto;
}
.pwd-box input[type="number"] {
width: 100%;
height: 36.5px;
position: absolute;
top: 0;
left: 0;
border: 0;
font-size: 18px;
opacity: 0;
z-index: 1;
letter-spacing: 30px;
padding: 0;
}
.fake-box input {
padding: 0;
width: 36.5px;
height: 36.5px;
border: 0;
border-right: 1px solid #E5E5E5;
text-align: center;
font-size: 30px;
background-color: transparent;
float: left;
}
.fake-box input:nth-last-child(1) {
border: 0;
}
.button {
width: 224px;
height: 42px;
line-height: 42px;
color: #fff;
background-color: #2B86E3;
border-radius: 5px;
text-align: center;
margin: 20px auto 0;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />
<title>6位密码弹窗</title>
<link rel="shortcut icon" href="#" />
<link rel="stylesheet" href="./css/style.css" />
</head>
<body>
<div class="button showPop">点击显示弹窗</div>
<div class="pop-box">
<div class="mask"></div>
<div class="pwd-wrapper">
<div class="pwd-top">
<div class="title">请输入支付密码</div>
<img class="close" src="images/close.png" alt="" />
</div>
<div class="pwd-box">
<input type="number" maxlength="6" class="pwd-input" id="pwd-input" oninput="if(value.length>6) value=value.slice(0,6)" />
<div class="fake-box">
<input type="password" readonly="" />
<input type="password" readonly="" />
<input type="password" readonly="" />
<input type="password" readonly="" />
<input type="password" readonly="" />
<input type="password" readonly="" />
</div>
</div>
</div>
</div>
<script src="./js/jquery-1.11.0.min.js"></script>
<script>
$(function() {
var $inputs = $(".fake-box input");
// 点击显示弹窗
$('.showPop').click(function(event) {
$('.pop-box').fadeIn('slow');
$("#pwd-input").focus();
});
// 点击关闭弹窗
$('.mask, .close').click(function(event) {
$('.pop-box').fadeOut('fast');
clearPwd($inputs);
});
// 加载显示密码函数
showPwd($inputs);
// 点击弹窗
$('.pwd-wrapper').click(function(event) {
$("#pwd-input").focus();
});
});
// 显示六位密码
function showPwd($inputs) {
$("#pwd-input").on("input", function() {
var pwd = $(this).val().trim();
// 渲染到密码框
for (var i = 0, len = pwd.length; i < len; i++) {
$inputs.eq(i).val(pwd[i]);
}
// 用于处理回退的问题
$inputs.each(function() {
var index = $(this).index();
if (index >= len) {
$(this).val("");
}
});
// 输入6位执行其他操作
if (len == 6) {
// console.log(pwd);
$('.mask, .close').trigger('click');
}
});
}
// 清除输入数据
function clearPwd($inputs) {
$("#pwd-input").val("");
$inputs.each(function() {
$(this).val("");
});
}
</script>
</body>
</html>
猜你喜欢
- 2024-09-11 浅析MySQL Join Reorder算法(mysqlinner join)
- 2024-09-11 js 小函数(js函数总结)
- 2024-09-11 Kubernetes 高性能网络组件 Calico 入门教程
- 2024-09-11 jQuery中的clone妙用(jquery.on)
- 2024-09-11 自定义一个"骚气"的jQuery
- 2024-09-11 前端单元测试以及自动化构建入门(前端单元测试是什么)
- 2024-09-11 Python全栈 Web(jQuery 一条龙服务)
- 2024-09-11 jQuery遍历说、详解与示例的结合,轻松搞定这个遍历!
- 2024-09-11 「clickhouse专栏」对标mongodb存储类JSON数据文档统计分析
- 2024-09-11 jQuery实现简易购物车功能(jquery购物车结算页面)
- 02-21走进git时代, 你该怎么玩?_gits
- 02-21GitHub是什么?它可不仅仅是云中的Git版本控制器
- 02-21Git常用操作总结_git基本用法
- 02-21为什么互联网巨头使用Git而放弃SVN?(含核心命令与原理)
- 02-21Git 高级用法,喜欢就拿去用_git基本用法
- 02-21Git常用命令和Git团队使用规范指南
- 02-21总结几个常用的Git命令的使用方法
- 02-21Git工作原理和常用指令_git原理详解
- 最近发表
- 标签列表
-
- cmd/c (57)
- c++中::是什么意思 (57)
- sqlset (59)
- ps可以打开pdf格式吗 (58)
- phprequire_once (61)
- localstorage.removeitem (74)
- routermode (59)
- vector线程安全吗 (70)
- & (66)
- java (73)
- org.redisson (64)
- log.warn (60)
- cannotinstantiatethetype (62)
- js数组插入 (83)
- resttemplateokhttp (59)
- gormwherein (64)
- linux删除一个文件夹 (65)
- mac安装java (72)
- reader.onload (61)
- outofmemoryerror是什么意思 (64)
- flask文件上传 (63)
- eacces (67)
- 查看mysql是否启动 (70)
- java是值传递还是引用传递 (58)
- 无效的列索引 (74)