JQuery: How to get selected radio button value?

前端 未结 11 1274
北海茫月
北海茫月 2020-12-08 06:50

How do I default the value of a non-selected radio button to 0?

I have the following HTML:



        
11条回答
  •  生来不讨喜
    2020-12-08 07:17

    You should really be using checkboxes if there will be an instance where something isn't selected.

    according to the W3C

    If no radio button in a set sharing the same control name is initially "on", user agent behavior for choosing which control is initially "on" is undefined. Note. Since existing implementations handle this case differently, the current specification differs from RFC 1866 ([RFC1866] section 8.1.2.4), which states:

    At all times, exactly one of the radio buttons in a set is checked. If none of the elements of a set of radio buttons specifies `CHECKED', then the user agent must check the first radio button of the set initially.

    Since user agent behavior differs, authors should ensure that in each set of radio buttons that one is initially "on".

提交回复
热议问题