Disable scrolling on `<input type=number>`

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

    You can simply use the HTML onwheel attribute.

    This option have no effects on scrolling over other elements of the page.

    And add a listener for all inputs don't work in inputs dynamically created posteriorly.

    Aditionaly, you can remove the input arrows with CSS.

    input[type="number"]::-webkit-outer-spin-button, 
    input[type="number"]::-webkit-inner-spin-button {
        -webkit-appearance: none;
        margin: 0;
    }
    input[type="number"] {
        -moz-appearance: textfield;
    }

提交回复
热议问题