Как да проверите радио бутон с jQuery?

Опитвам се да проверя радио бутон с jQuery. Ето моя код:

<form>
    <div id='type'>
        <input type='radio' id='radio_1' name='type' value='1' />
        <input type='radio' id='radio_2' name='type' value='2' />
        <input type='radio' id='radio_3' name='type' value='3' /> 
    </div>
</form>

И JavaScript:

jQuery("#radio_1").attr('checked', true);

Не работи:

jQuery("input[value='1']").attr('checked', true);

Doesn't work:

jQuery('input:radio[name="type"]').filter('[value="1"]').attr('checked', true);

Doesn't work:

Имате ли друга идея? Какво пропускам?

Решение

За версии на jQuery, равни или по-големи от (>=) 1.6, използвайте:

$("#radio_1").prop("checked", true);

За версии преди (

Коментари (15)

Трябва да направите

jQuery("#radio_1").attr('checked', 'checked');

Това е атрибутът на HTML

Коментари (0)
$("#radio_1").attr('checked', true);
//or
$("#radio_1").attr('checked', 'checked');
Коментари (2)