javascript - input 为 text时,怎么控制它的值最大为199,最小为3?
巴扎黑
巴扎黑 2017-04-11 11:27:54
0
2
224
<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';
                            }
                        });
                    }
                });
巴扎黑
巴扎黑

reply all(2)
洪涛

给两种简单的思路
1.如果要在提交时进行判断,可以取出输入的数字去做判断
2.如果要在输入时进行判断,可以在input上绑定chang事件判断。

阿神

这个完全可以用jquery控制啊,你可以在提交表单时候判断,或者在blur判断,应该都是有作用的

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!