提现对输入框输入的数进行判定
<input id='num' oninput="changes()" type="number" placeholder="请输入提现金额">
<div class="btns_bg" onclick="transFer()">确认提现</div>
function changes() {
$api.val(num, ($.trim($api.val(num)).match(/^\d*(\.?\d{0,1})/g)[0]) || null);
if (from() == 10) {
$api.addCls($api.dom('.btns div:first-child'), 'btns_top');
} else {
$api.removeCls($api.dom('.btns div:first-child'), 'btns_top');
};
}
function from() {
var x= Number(document.getElementById("num").value)
if ($.trim($api.val(num)).length < 0.1) {
return 0;
}
if (x > textmoneya) {//如果大于能提现的钱
return 5;
}
if (mibble == null){//如果未绑定 id为空
return 2;
}
return 10;
}
function transFer() {
switch (from()) {
case 0:
api.toast({
msg: '请输入提现金额',
duration: 2000,
location: 'middle'
});
break;
case 2:
api.toast({
msg: '请绑定支付宝',
duration: 2000,
location: 'middle'
});
break;
case 5:
api.toast({
msg: '余额不足',
duration: 2000,
location: 'middle'
});
break;
case 10:
if ($.trim($api.val($api.dom("#num"))) < 0.1) {
api.toast({
msg: '账户余额没有满足最低提现金额(0.1元)不能提现',
duration: 3000,
location: 'middle'
});
break;
};
$api.ajax({
url: 'http://xxxxxxxxxxxxxxx',
method: 'get',
data: {
values: {
money: $.trim($api.val($api.dom("#num"))),
userId: uid
}
}
}, function(ret) {
api.toast({
msg: ret.msg,
duration: 2000,
location: 'middle'
});
setTimeout(() => {
back()
}, 2000);
});
};
}
本文详细介绍了如何使用JavaScript实现一个提现功能,包括对输入金额的实时验证,判断金额是否合法,以及根据不同情况给出相应的提示信息。同时,还展示了如何通过Ajax进行后台请求,完成提现操作。

被折叠的 条评论
为什么被折叠?



