Disable scrolling on `<input type=number>`

后端 未结 15 1799
小蘑菇
小蘑菇 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:13

    Typescript Variation

    Typescript needs to know that you're working with an HTMLElement for type safety, else you'll see lots of Property 'type' does not exist on type 'Element' type of errors.

    document.addEventListener("mousewheel", function(event){
      let numberInput = (document.activeElement);
      if (numberInput.type === "number") {
        numberInput.blur();
      }
    });
    

提交回复
热议问题