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仿京东商品放大浏览页面
Jun 06 jQuery
基于jQuery封装的分页组件
Jun 26 jQuery
jquery实现下拉菜单的手风琴效果
Jul 23 jQuery
JS与jQuery实现ListBox上移,下移,左移,右移操作功能示例
May 31 jQuery
jQuery+Datatables实现表格批量删除功能【推荐】
Oct 24 jQuery
Vue CLI3.0中使用jQuery和Bootstrap的方法
Feb 28 jQuery
jQuery 判断元素是否存在然后按需加载内容的实现代码
Jan 16 jQuery
jquery css实现流程进度条
Mar 26 jQuery
jQuery实现二级导航菜单的示例
Sep 30 jQuery
Jquery Fade用法详解
Nov 06 jQuery
jQuery实现查看图片功能
Dec 01 jQuery
jquery自定义组件实例详解
Dec 31 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
3款值得推荐的微信开发开源框架
2014/10/28 PHP
PHP不使用递归的无限级分类简单实例
2016/11/05 PHP
PHP实现模拟http请求的方法分析
2017/12/20 PHP
兼容IE和FF的js脚本代码小结(比较常用)
2010/12/06 Javascript
js内置对象 学习笔记
2011/08/01 Javascript
$.getJSON在IE下失效的原因分析及解决方法
2013/06/16 Javascript
js中的referrer返回上一页使用介绍
2013/09/26 Javascript
JavaScript判断表单为空及获取焦点的方法
2016/02/12 Javascript
JS组件Bootstrap dropdown组件扩展hover事件
2016/04/17 Javascript
D3.js实现折线图的方法详解
2016/09/21 Javascript
正则验证小数点后面只能有两位数的方法
2017/02/28 Javascript
html+javascript+bootstrap实现层级多选框全层全选和多选功能
2017/03/09 Javascript
vue 自定义全局方法,在组件里面的使用介绍
2018/02/28 Javascript
解决angular2 获取到的数据无法实时更新的问题
2018/08/31 Javascript
JavaScript基于数组实现的栈与队列操作示例
2018/12/22 Javascript
Vue.js watch监视属性知识点总结
2019/11/11 Javascript
Pandas 数据处理,数据清洗详解
2018/07/10 Python
pygame游戏之旅 添加游戏暂停功能
2018/11/21 Python
python实现鸢尾花三种聚类算法(K-means,AGNES,DBScan)
2019/06/27 Python
python3实现网页版raspberry pi(树莓派)小车控制
2020/02/12 Python
python re模块常见用法例举
2021/03/01 Python
加拿大廉价机票预订网站:CheapOair.ca
2018/03/04 全球购物
英国索普公园票务和酒店套餐:Thorpe Breaks
2019/09/14 全球购物
建材业务员岗位职责
2013/12/08 职场文书
师范学院美术系毕业生自我鉴定
2014/01/29 职场文书
《寓言两则》教学反思
2014/02/27 职场文书
集团公司党的群众路线教育实践活动工作总结
2014/03/03 职场文书
《晚上的太阳》教学反思
2014/04/23 职场文书
业务内勤岗位职责
2014/04/30 职场文书
技校毕业生自荐信
2014/06/03 职场文书
生活小常识广播稿
2014/09/16 职场文书
新闻通讯稿模板
2015/07/22 职场文书
《有余数的除法》教学反思
2016/02/22 职场文书
求职信:求职应该注意的问题
2019/04/24 职场文书
导游词之崇武古城
2019/10/07 职场文书
基于python实现银行管理系统
2021/04/20 Python