我表单中的最大输入数值

时间:2018-02-19 07:59:59

标签: forms input

我尝试以此格式enter link description here

将最大数量设置为10

请问怎么可能这样做? 谢谢

1 个答案:

答案 0 :(得分:0)

请尝试在代码中添加验证:

   $('.qtyplus').click(function(e){
            // Stop acting like a button
            e.preventDefault();
            // Get the field name
            fieldName = $(this).attr('name');
            // Get its current value
            var currentVal = parseInt($('input[name='+fieldName+']').val());
            // If is not undefined
            if (!isNaN(currentVal) && currentVal < 10) {
                // Increment
                $('input[name='+fieldName+']').val(currentVal + 1);
            } else {
                // Otherwise put a 0 there
                $('input[name='+fieldName+']').val(1);
            }
        });