jQueryUI Radio/Check buttons not changing programmatically

I can predicably read the value of a jQueryUI radio button, however, I am not able to set it programmatically. No matter which methods I use to change the radio button's value, jQueryUI interface will not update its interface.

<div id="radio">
    <input type="radio" name="radio" value="true" checked="checked" />Yes
    <input type="radio" name="radio" value="false" />No
</div>

<script type="text/javascript">
    $('#radio').buttonset();

    // One of the many ways that won't work.
    $('[name="radio"]:radio:checked').val("false");
</script>
11
задан rebelliard 31 August 2015 в 14:05
поделиться

2 ответа

После обновления значения, например:

$('[name="radio"][value="false"]').attr("checked", true);

Вам нужно указать jQuery UI на обновление, например:

$('#radio').buttonset("refresh");

Вы можете попробовать здесь .

20
ответ дан 3 December 2019 в 02:19
поделиться
$('[name="state"]:radio:checked').attr('checked', true);   // checked
$('[name="state"]:radio:checked').removeAttr('checked');   // unchecked

** ПРИМЕЧАНИЕ **

$(':radio').val();  // same as $(':radio').attr('value');

Таким образом:

$(':radio[checked]').val(); // -> the value of the first checked radio button found
4
ответ дан 3 December 2019 в 02:19
поделиться
Другие вопросы по тегам:

Похожие вопросы: