How to make type=“number” to positive numbers only

后端 未结 17 2432
既然无缘
既然无缘 2020-11-30 17:12

currently I have the following code


it comes out to something like this

17条回答
  •  执念已碎
    2020-11-30 18:03

    Other solution is to use Js to make it positive (min option can be disabled and is not valid when the user types smth) The negative if is not necessary and on('keydown') event can also be used!

    let $numberInput =  $('#whatEverId');
    $numberInput.on('change', function(){
        let numberInputText = $numberInput.val();
        if(numberInputText.includes('-')){
            $numberInput.val(Math.abs($numberInput.val()));
        }
    });
    

提交回复
热议问题