我可以预测地读取jQueryUI单选按钮的值,但是我不能以编程方式设置它。无论我使用哪种方法来更改单选按钮的值,jQueryUI界面都不会更新其界面。
<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>发布于 2010-08-26 04:13:08
更新该值后,如下所示:
$('[name="radio"][value="false"]').attr("checked", true);您需要通知jQuery UI进行更新,如下所示:
$('#radio').buttonset("refresh");You can give it a try here。
发布于 2011-05-26 18:52:58
我通常会做一个:
$('[name="radio"][value="false"]').attr("checked", true).trigger("change");buttonset("refresh")调用被绑定到change事件,当您以编程方式更改值时不会触发该事件-手动触发它可以解决ui问题,并且您无需担心按钮集在哪里
发布于 2010-08-26 04:08:52
$('[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 foundhttps://stackoverflow.com/questions/3569794
复制相似问题