Restrict user to put value in range in html input (type = number)

后端 未结 4 2004
清歌不尽
清歌不尽 2021-01-06 01:41

How can I stop user from adding number greater than max value and smaller then min value in html input(type = number)



        
4条回答
  •  说谎
    说谎 (楼主)
    2021-01-06 02:24

    Try this:

    var max = 100;
    $('input').keyup(function(){
    
    var inputValue = $(this).val();
    if(inputValue > max){
        alert('greater!');
    
        $(this).val('')
    }
    

    })

    here is jsfiddle: http://jsfiddle.net/h07Lc0Ld/1/

提交回复
热议问题