HTML number input min and max not working properly

前端 未结 12 1745
野的像风
野的像风 2020-12-05 22:31

I have type=number input field and I have set min and max values for it:



        
12条回答
  •  感动是毒
    2020-12-05 22:50

    $(document).ready(function(){
        $('input[type="number"]').on('keyup',function(){
            v = parseInt($(this).val());
            min = parseInt($(this).attr('min'));
            max = parseInt($(this).attr('max'));
    
            /*if (v < min){
                $(this).val(min);
            } else */if (v > max){
                $(this).val(max);
            }
        })
    })
    

    Here is my contribution. Note that the v < min is commented out because I'm using Bootstrap which kindly points out to the user that the range is outside the 1-100 but wierdly doesn't highlight > max!

提交回复
热议问题