Disable scrolling on `<input type=number>`

后端 未结 15 1805
小蘑菇
小蘑菇 2020-12-02 07:13

Is it possible to disable the scroll wheel changing the number in an input number field? I\'ve messed with webkit-specific CSS to remove the spinner but I\'d like to get rid

15条回答
  •  鱼传尺愫
    2020-12-02 08:00

    @Semyon Perepelitsa

    There is a better solution for this. Blur removes the focus from the input and that is a side affect that you do not want. You should use evt.preventDefault instead. This prevents the default behavior of the input when the user scrolls. Here is the code:

    input = document.getElementById("the_number_input")
    input.addEventListener("mousewheel", function(evt){ evt.preventDefault(); })
    

提交回复
热议问题