The event selection of checkbox and radio once confused me.
Based on my understanding of js, I think the change event should be the most reasonable. Unfortunately, ie, the change event is only triggered when the focus leaves after the change.
Later, mouse events such as click mousedown were used instead. I found that click is more perfect than mousedown:
After radio registers the click event, the magic is that when you select up, down, left, and right on the keyboard, the mouse event will be triggered, and the scroll wheel will also be triggered. This magical thing This will not happen under mousedown. (Webkit cannot use up, down, left, and right selections)
After the checkbox registers the click event, the miracle happens again. When we select the checkbox with a space, the magical click event is triggered again, and the mousedown misses the miracle again. (Webkit still cannot use spaces to select)
Let us all use click to reduce the burden on these two guys. Don’t bind a bunch of events to them because of their inherent shortcomings. For these two guys, click is the best Almighty. Worship~~~
When designing a questionnaire using a form, in order to reduce user operations, it is a good idea to use a select box. There are two select boxes in the tag of HTML, namely single The difference between a select box and a check box is that users can only select one option in a radio button box, while users can select multiple options in a check box, or even select all of them. Please look at the following example:
The source code of this example is given below. Combined with the code, the settings of each parameter are discussed: