jquery sets, judges, and gets the selected state of the input single-selection label

1. Set a single-selection input to the selected state:
①Set its attribute checked to true

$("input[type='radio']").eq(1).attr('checked',true);

②You can also set its attribute checked to'checked', and the original selected item will be automatically unchecked after setting

$("input[type='radio']").eq(1).attr('checked','checked');

2. Determine whether a radio button is selected :

❶ 使用object.attr(‘checked’)true is wrong, object.attr('checked') should be used'checked' for judgment

$("input[type='radio']").eq(1).attr('checked')=='checked';

❷The is(':checked') method can also be used for judgment

$("input[type='radio']").eq(1).is(':checked');

3. Get the selected radio button: use the :checked method

$("input[type='radio']:checked");

Guess you like

Origin blog.csdn.net/qq_41353397/article/details/114241829