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

全部回复(2)
PHP中文网

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

阿神

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号