Jquery+javascript實(shí)現(xiàn)支付網(wǎng)頁數(shù)字鍵盤
Jquery+javascript動(dòng)態(tài)生成支付網(wǎng)頁數(shù)字鍵盤
制作網(wǎng)頁支付界面的時(shí)候,數(shù)字鍵盤適配不同的屏幕寬高比是一個(gè)很麻煩的事,所以我制作了一個(gè)根據(jù)屏幕寬高動(dòng)態(tài)生成的數(shù)字鍵盤
運(yùn)行截圖:

實(shí)現(xiàn)代碼
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>動(dòng)態(tài)數(shù)字鍵盤</title>
</head>
<body>
<div class="pay-top">
<img class="lklogo" src="img/lianke.png">
<div class="pay-shop-info">
<span class="shop-name">付款給:{{付款對(duì)象名}}</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>確認(rèn)</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>
<!--自適應(yīng)布局-->
<script>
(function () {
var designW = 750; //設(shè)計(jì)稿寬
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";
//監(jiān)測(cè)窗口大小變化
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;
}
附帶上退格符,將其放項(xiàng)目的img文件中,否則數(shù)字鍵盤退格符無法顯示:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
原生JS實(shí)現(xiàn)幾個(gè)常用DOM操作API實(shí)例
下面小編就為大家?guī)硪黄鶭S實(shí)現(xiàn)幾個(gè)常用DOM操作API實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-01-01
根據(jù)身份證號(hào)自動(dòng)輸出相關(guān)信息(籍貫,出身日期,性別)
為了減少客戶的在頁面的輸入,做了這個(gè)效果,他可以根據(jù)用戶輸入的身份證號(hào)輸出籍貫、出身日期、性別的相關(guān)信息,需要的朋友可以參考下2013-11-11
JavaScript簡(jiǎn)單實(shí)現(xiàn)彈出拖拽窗口(一)
這篇文章主要為大家詳細(xì)介紹了JavaScript簡(jiǎn)單實(shí)現(xiàn)彈出拖拽窗口的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-06-06
實(shí)例分析js和C#中使用正則表達(dá)式匹配a標(biāo)簽
本文通過2個(gè)實(shí)例,對(duì)比分析了在js和c#中使用正則表達(dá)式匹配a標(biāo)簽的異同,小伙伴們自己參考下吧,有利于深刻理解正則表達(dá)式的使用。2014-11-11
js對(duì)象屬性名駝峰式轉(zhuǎn)下劃線的實(shí)例代碼
這篇文章主要介紹了js對(duì)象屬性名駝峰式轉(zhuǎn)下劃線的實(shí)例代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-09-09
JavaScript指定字段排序方法sortFun函數(shù)
這篇文章主要介紹了JavaScript指定字段排序方法sortFun函數(shù),數(shù)組的排序方法是sort,但是它并不支持根據(jù)指定的字段進(jìn)行排序,而sortFun可以根據(jù)指定的字段進(jìn)行排序,需要的朋友可以參考下2023-05-05
JavaScript設(shè)計(jì)模式之門面模式原理與實(shí)現(xiàn)方法分析
這篇文章主要介紹了JavaScript設(shè)計(jì)模式之門面模式原理與實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了門面模式的原理、實(shí)現(xiàn)方法及操作注意事項(xiàng),需要的朋友可以參考下2020-03-03
websocket4.0+typescript 實(shí)現(xiàn)熱更新的方法
這篇文章主要介紹了websocket4.0+typescript 實(shí)現(xiàn)熱更新的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
javascript放大鏡效果的簡(jiǎn)單實(shí)現(xiàn)
這篇文章主要是對(duì)javascript放大鏡效果的簡(jiǎn)單實(shí)現(xiàn)進(jìn)行了介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助2013-12-12
uniapp頁面間傳參的幾種方法實(shí)例總結(jié)
在進(jìn)行頁面的跳轉(zhuǎn)的時(shí)候,往往需要我們將一些參數(shù)攜帶著傳遞過去,下面這篇文章主要給大家介紹了關(guān)于uniapp頁面間傳參的幾種方法,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-12-12

