Why does jQuery .change() not fire on radio buttons deselected as a result of a namesake being selected?

后端 未结 3 524
执念已碎
执念已碎 2021-01-18 04:57

If I have several radio buttons of the same name, only one can be selected at any one time. When one becomes selected, any namesakes lose their selection. I\'m intrigued as

3条回答
  •  梦谈多话
    2021-01-18 05:21

    If you think of a set of radio buttons like a select element, it becomes clear why it's unnecessary to fire a change event for the deselected radio button.

    When you change the selected option in a select element, you get one change event (you wouldn't expect anything else), rather than one for the previously selected option, and another for the newly selected option.

    As has already been mentioned, when one radio button is selected, no others in the same set can be, so it would be redundant to fire a second change event.

    Also note that this is not specific to jQuery - the standard JavaScript change event works in exactly the same way.

提交回复
热议问题