在jquery mobile中,我想用javascript代码更改单选组。我有这个:
<fieldset data-role="controlgroup" data-type="horizontal" data-mini="true">
<legend>Co-op Department:</legend>
<input name="coopdepartment" id="artssciRB" value="Arts & Science" checked="checked" type="radio">
<label for="artssciRB">Arts & Science</label>
<input name="coopdepartment" id="managementRB" value="Management" type="radio">
<label for="managementRB">Management</label>
<input name="coopdepartment" id="idsRB" value="IDS" type="radio">
<label for="idsRB">IDS</label>
</fieldset>
JS
var all = $("#profile-edit-form").find("input");
all.removeAttr("checked");
$("#profile-edit-form").find("input[value="+user['department_name']+"]").attr( "checked", "checked" );
all.checkboxradio( "refresh" );
但它不起作用...有人知道出了什么问题吗?不过,它在输入标记上放置了一个选中的属性。
谢谢
最佳答案
.attr()
指的是实际标记中的 HTML 属性。您想要使用的不是 HTML 属性,而是元素的 DOM 属性。您需要 .prop('checked')
来实现此目的,而不是 .attr('checked')
。
关于javascript - 如何使用javascript代码更改jquery移动单选按钮组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28334286/