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

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

I have an input:


And I don\'t have

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-21 05:29

    The user is expected to be able to type in the field, as one option. Although it is possible to prevent this in part (namely when JavaScript is enabled and event handlers in your code cover the ways that the user might use), there is no point in using the element when you specifically do not want to get its basic functionality.

    If you only want to allow the two values 4 and 6, as it seems from your example, and you want to prevent the user from simply typing one of them, then you should use a select element or a set of two radio buttons.

提交回复
热议问题