Is there a way to stop manual input in a type=number but still allow changes with the “up/down” buttons?

后端 未结 5 580
鱼传尺愫
鱼传尺愫 2020-12-21 04:35

I have an input:


And I don\'t have

5条回答
  •  太阳男子
    2020-12-21 05:19

    Try it dude, my problem was solved

    var prevVal = 0;
    $("input[type=number]").on("keydown", function(e){
        prevVal = Number($(this).val());
    });
    $("input[type=number]").on("keyup", function(e){
       var minVal = $(this).attr("min");
        var maxVal = $(this).attr("max");
        var step= $(this).attr("step");
        var currentVal = $(this).val();
        if(!(currentVal>=1)){
            $(this).val(1)
        }
    
    });

提交回复
热议问题