javascript - input 为 text时,怎么控制它的值最大为199,最小为3?
本文介绍了javascript - input 为 text时,怎么控制它的值最大为199,最小为3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
<input id="dialogPrice" type="text" class="weui-input" placeholder="¥10" />
试了好多办法都不起作用。
下面是我的代码:
//其它金额
$('#otherPriceBtn').on('click', function(e) {
var otherPrice = $('#dialogPrice').val();
getOtherPrice = otherPrice >= 3 && otherPrice <= 199;
if(getOtherPrice) {
weui.topTips('请输入3~199之间的金额!');
} else {
console.log("其它金额" + otherPrice);
var data = {
userId: userId,
price: otherPrice
};
data = JSON.stringify(data);
$.ajax({
data: {},
dataType: 'json',
type: "post",
url: url,
contentType: 'application/json; charset=utf-8',
success: function(data) {
},
error: function(data) {
location.href = 'doctor_wode.html';
}
});
}
});
解决方案
给两种简单的思路
1.如果要在提交时进行判断,可以取出输入的数字去做判断
2.如果要在输入时进行判断,可以在input上绑定chang事件判断。
这篇关于javascript - input 为 text时,怎么控制它的值最大为199,最小为3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文