Jquery+javascript实现支付网页数字键盘


Posted in jQuery onDecember 21, 2020

Jquery+javascript动态生成支付网页数字键盘

制作网页支付界面的时候,数字键盘适配不同的屏幕宽高比是一个很麻烦的事,所以我制作了一个根据屏幕宽高动态生成的数字键盘

运行截图:

Jquery+javascript实现支付网页数字键盘

实现代码

html:

<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <meta content="initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
 <meta content="yes" name="apple-mobile-web-app-capable">
 <meta content="black" name="apple-mobile-web-app-status-bar-style">
 <meta content="telephone=no" name="format-detection">
 <meta content="email=no" name="format-detection">
 <link rel="stylesheet" href="{{你的css文件路径}}" >
 <title>动态数字键盘</title>
</head>
<body>
 <div class="pay-top">
 <img class="lklogo" src="img/lianke.png">
 <div class="pay-shop-info">
 <span class="shop-name">付款给:{{付款对象名}}</span>
 </div>
 <div class="paymoneylogo">
 <span>¥</span>
 </div>
 <label class="inputlabel" id="paymoney" type="text"></label>
 </div>
 <div class="payinfo">
 <table cellspacing="0" cellpadding="0">
 <tr>
 <td class="paynum">1</td>
 <td class="paynum">2</td>
 <td class="paynum">3</td>
 <td id="pay-return">
  <div class="keybord-return"></div>
 </td>
 </tr>
 <tr>
 <td class="paynum">4</td>
 <td class="paynum">5</td>
 <td class="paynum">6</td>
 <td rowspan="3" class="pay">
  <a href="javascript:return false;" >
  <div class="a-pay">
  <p>确认</p>
  <p>支付</p>
  </div>
  </a>
 </td>
 </tr>
 <tr>
 <td class="paynum">7</td>
 <td class="paynum">8</td>
 <td class="paynum">9</td>
 </tr>
 <tr>
 <td id="pay-zero" colspan="2" class="payzero">0</td>
 <td id="pay-float">.</td>
 </tr>
 </table>
 </div>
</body>
<script src="./js/jquery.js"></script>
<script type="text/javascript">
 $(function () {
 $(".payinfo").slideDown();
 var $paymoney = $("#paymoney");
 $("#paymoney").focus(function () {
 $(".payinfo").slideDown();
 document.activeElement.blur();
 });
 $(".paynum").each(function () {
 $(this).click(function () {
 if (($paymoney.text()).indexOf(".") != -1 && ($paymoney.text()).substring(($paymoney.text()).indexOf(".") + 1, ($paymoney.text()).length).length == 2) {
  return;
 }
 if ($.trim($paymoney.text()) == "0") {
  return;
 }
 if (parseInt($paymoney.text()) > 10000 && $paymoney.text().indexOf(".") == -1) {
  return;
 }
 $paymoney.text($paymoney.text() + $(this).text());
 });
 });

 $("#pay-return").click(function () {
 $paymoney.text(($paymoney.text()).substring(0, ($paymoney.text()).length - 1));
 if (!$paymoney.text()) {
 $('.pay').addClass('pay-disabled').find('a').attr('href', 'javascript:return false;');
 }
 });

 $("#pay-zero").click(function () {
 if (($paymoney.text()).indexOf(".") != -1 && ($paymoney.text()).substring(($paymoney.text()).indexOf(".") + 1, ($paymoney.text()).length).length == 2) {
 return;
 }
 if ($.trim($paymoney.text()) == "0") {
 return;
 }
 if (parseInt($paymoney.text()) > 10000 && $paymoney.text().indexOf(".") == -1) {
 return;
 }
 $paymoney.text($paymoney.text() + $(this).text());
 });

 $("#pay-float").click(function () {
 if ($.trim($paymoney.text()) == "") {
 return;
 }

 if (($paymoney.text()).indexOf(".") != -1) {
 return;
 }

 if (($paymoney.text()).indexOf(".") != -1) {
 return;
 }
 $paymoney.text($paymoney.text() + $(this).text());
 });
 $('.pay').click(function () {
 alert("支付金额为"+$paymoney.text())
 });
 })
</script> 
<!--自适应布局-->
<script>
 (function () {
 var designW = 750; //设计稿宽
 var font_rate = 100;
 //适配
 document.getElementsByTagName("html")[0].style.fontSize = document.body.offsetWidth / designW * font_rate + "px";
 document.getElementsByTagName("body")[0].style.fontSize = document.body.offsetWidth / designW * font_rate + "px";

 //监测窗口大小变化
 window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", function () {
 document.getElementsByTagName("html")[0].style.fontSize = document.body.offsetWidth / designW * font_rate + "px";
 document.getElementsByTagName("body")[0].style.fontSize = document.body.offsetWidth / designW * font_rate + "px";
 }, false);
 })();
</script>
</html>

css

@CHARSET "UTF-8";
html,body{
 background-color:#fff;
}
.pay-top{
 position: absolute;
 width: 100%;
 height:60%;
 background: #fff;
}
.pay-shop-info {
 position: absolute;
 width: 90%;
 left:5%;
 text-align: right;
 top:3.4rem;
 font-size:0.3rem ;
 }

.paymoneylogo {
 position: absolute;
 width: 90%;
 left:5%;
 top:4rem;
 height: 1.3rem;
 border-bottom: 0.02rem solid #bfbfbf;
 -webkit-border-radius: 0.02rem;
 -moz-border-radius: 0.02rem;
 border-radius: 0.02rem;
 background: #fff;
}
.inputlabel{
 position: absolute;
 width: 90%;
 left:5%;
 top:4rem;
 height: 1.3rem;
 text-align: right;
}
.lklogo{
 position: absolute;
 height: 1.2rem;
 width: 50%;
 left:25%;
 top:0.8rem;
}
.payinfo{
 display:none;
}
.payinfo .paynum {
 font-size: 0.6rem;
 color: #424857;
}

.payinfo .payzero {
 font-size: 0.6rem;
 color: #424857;
}
table{
 width:100%; 
 height:50%;
 position:absolute;
 bottom:0;
 background-color:white;
 background-top:none;
}
table tr td{
 text-align:center;
 width: 1.88rem;
 height: 1.26rem;
 font-family: "Microsoft YaHei";
 font-weight: normal;
 border-right:1px solid #D9D9D9;
 border-top:1px solid #D9D9D9;
}
table tr td:active{
 background-color:#ECECEC;
}
.keybord-return{
 width: 1.88rem;
 height: 1.26rem;
 background:url(../img/keybord_return.png) no-repeat;
 background-size: 50% 50%;
 background-position: center;
}
.pay{
 color:#fff;
 font-size:0.4rem;
 background-color:#0259a1; 
}
.pay:active{
 background-color: #004198;
}
.pay a{
 display: block;
 position: relative;
 width: 100%;
 height: 100%;
 color: #fff;
 text-decoration: none; 
}
.a-pay {
 position: absolute;
 top: 50%;
 left: 50%;
 -webkit-transform: translate(-50%, -50%);
 -o-transform: translate(-50%, -50%);
 -moz-transform: translate(-50%, -50%);
 transform: translate(-50%, -50%);
}
.pay-disabled {
 background-color: #0259a1;
}

附带上退格符,将其放项目的img文件中,否则数字键盘退格符无法显示:

Jquery+javascript实现支付网页数字键盘

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

jQuery 相关文章推荐
jquery实现tab键进行选择后enter键触发click行为
Mar 29 jQuery
jquery点赞功能实现代码 点个赞吧!
May 29 jQuery
jQuery日期范围选择器附源码下载
May 23 jQuery
jQuery实现手机号正则验证输入及自动填充空格功能
Jan 02 jQuery
jQuery+ajax实现动态添加表格tr td功能示例
Apr 23 jQuery
AJAX在JQuery中的应用详解
Jan 30 jQuery
jQuery实现移动端图片上传预览组件的方法分析
May 01 jQuery
jQuery实现B2B网站后台管理系统侧导航
Jul 08 jQuery
jquery实现有过渡效果的tab切换
Jul 17 jQuery
jQuery实现雪花飘落效果
Aug 02 jQuery
JQuery Ajax如何实现注册检测用户名
Sep 25 jQuery
jQuery实现计算器功能
Oct 19 jQuery
jquery实现淡入淡出轮播图效果
Dec 13 #jQuery
jquery实现拖拽小方块效果
Dec 10 #jQuery
jQuery实现简单弹幕制作
Dec 10 #jQuery
JQuery绑定事件四种实现方法解析
Dec 02 #jQuery
jquery实现拖拽添加元素功能
Dec 01 #jQuery
jQuery实现可以扩展的日历
Dec 01 #jQuery
jQuery实现容器间的元素拖拽功能
Dec 01 #jQuery
You might like
php 执行系统命令的方法
2009/07/07 PHP
php正则表达式获取内容所有链接
2015/07/24 PHP
parseInt parseFloat js字符串转换数字
2010/08/01 Javascript
Javascript中自动切换焦点实现代码
2012/12/15 Javascript
简单的jquery左侧导航栏和页面选中效果
2014/08/21 Javascript
使用Chrome浏览器调试AngularJS应用的方法
2015/06/18 Javascript
javaScript数组迭代方法详解
2016/04/14 Javascript
AngularJS指令详解及示例代码
2016/08/16 Javascript
JavaScript 中 avalon绑定属性总结
2016/10/19 Javascript
Bootstrap下拉菜单Dropdowns的实现代码
2017/03/17 Javascript
js中toString()和String()区别详解
2017/03/23 Javascript
JSON在Javascript中的使用(eval和JSON.parse的区别)详细解析
2017/09/05 Javascript
Vue.js2.0中的变化小结
2017/10/24 Javascript
jQuery实现验证表单密码一致性及正则表达式验证邮箱、手机号的方法
2017/12/05 jQuery
vue.js内置组件之keep-alive组件使用
2018/07/10 Javascript
jQuery Ajax async=&gt;false异步改为同步时,解决导致浏览器假死的问题
2019/07/22 jQuery
python使用WMI检测windows系统信息、硬盘信息、网卡信息的方法
2015/05/15 Python
浅谈django rest jwt vue 跨域问题
2018/10/26 Python
实时获取Python的print输出流方法
2019/01/07 Python
Python函数定义及传参方式详解(4种)
2019/03/18 Python
对Python中TKinter模块中的Label组件实例详解
2019/06/14 Python
python读写csv文件并增加行列的实例代码
2019/08/01 Python
Python 私有化操作实例分析
2019/11/21 Python
win10下opencv-python特定版本手动安装与pip自动安装教程
2020/03/05 Python
django model object序列化实例
2020/03/13 Python
PyCharm Anaconda配置PyQt5开发环境及创建项目的教程详解
2020/03/24 Python
jupyter notebook读取/导出文件/图片实例
2020/04/16 Python
在matplotlib中改变figure的布局和大小实例
2020/04/23 Python
Pytorch环境搭建与基本语法
2020/06/03 Python
国外平面设计素材网站:The Hungry JPEG
2017/03/28 全球购物
工作中的自我评价如何写好
2013/10/28 职场文书
2014幼儿园教师师德师风演讲稿
2014/09/10 职场文书
乡镇党的群众路线教育实践活动个人整改方案
2014/10/31 职场文书
优秀护士事迹材料
2014/12/25 职场文书
标准版个人借条怎么写?以及什么是借条?
2019/08/28 职场文书
zabbix agent2 监控oracle数据库的方法
2021/05/13 Oracle