没有合适的资源?快使用搜索试试~ 我知道了~
js实现输入为0-10的数字,保留两位小数。
1星 需积分: 50 29 下载量 30 浏览量
2017-02-14
10:39:56
上传
评论
收藏 1KB TXT 举报
温馨提示
试读
2页
该程序使用js 可校验输入框 为0-10 两位数字,并可保留两位小数
资源推荐
资源详情
资源评论
页面部分:
<table class="section" border="0" cellspacing="0" cellpadding="0">
<tr class="trTwo">
<td>号码:</td>
<td><input type="text" class="inputTextStyle" id="presentPhoneNum" placeholder="请输入号码"/></td>
<td><span class="mLeft">金额:</span></td>
<td><input type="text" class="inputTextStyle" id="presentAmount" placeholder="不超过10元"/></td>
</tr>
<tr class="trThree">
<td><input type="text" style="display: none" id="phoneNumErrorFlag" value="0"/></td>
<td height="22px"><span class="prcieError" style="display: none" id="presentPhoneNumError">请正确录入号码</span></td>
<td><input type="text" style="display: none" id="amountErrorFlag" value="0"/></td>
<td height="22px"><span class="prcieError" style="display: none" id="presentAmountError">请正确录入金额</span></td>
</tr>
</table>
js部分:
$("#presentAmount").live("keyup",function(){
$("#presentAmountError").hide();
var price = $.trim($("#presentAmount").val());
if(price == "" && price == "") {
$("#amountErrorFlag").attr("value", "0");
return true;
}
var patt = new RegExp("^[0-9]{1}(\\.([0-9]{0,2}))?$|^10(\.[0]{0,2})?$");
if(!patt.test(price) || !patt.test(price)) {
$("#presentAmountError").show();
$("#amountErrorFlag").attr("value", "0");
return false;
}
$("#amountErrorFlag").attr("value", "1");
<table class="section" border="0" cellspacing="0" cellpadding="0">
<tr class="trTwo">
<td>号码:</td>
<td><input type="text" class="inputTextStyle" id="presentPhoneNum" placeholder="请输入号码"/></td>
<td><span class="mLeft">金额:</span></td>
<td><input type="text" class="inputTextStyle" id="presentAmount" placeholder="不超过10元"/></td>
</tr>
<tr class="trThree">
<td><input type="text" style="display: none" id="phoneNumErrorFlag" value="0"/></td>
<td height="22px"><span class="prcieError" style="display: none" id="presentPhoneNumError">请正确录入号码</span></td>
<td><input type="text" style="display: none" id="amountErrorFlag" value="0"/></td>
<td height="22px"><span class="prcieError" style="display: none" id="presentAmountError">请正确录入金额</span></td>
</tr>
</table>
js部分:
$("#presentAmount").live("keyup",function(){
$("#presentAmountError").hide();
var price = $.trim($("#presentAmount").val());
if(price == "" && price == "") {
$("#amountErrorFlag").attr("value", "0");
return true;
}
var patt = new RegExp("^[0-9]{1}(\\.([0-9]{0,2}))?$|^10(\.[0]{0,2})?$");
if(!patt.test(price) || !patt.test(price)) {
$("#presentAmountError").show();
$("#amountErrorFlag").attr("value", "0");
return false;
}
$("#amountErrorFlag").attr("value", "1");
资源评论
- qq3783372502018-02-27不可以保留小数
f625199688
- 粉丝: 2
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功