2015-02-05 58 views
0

在jquery mobile中,我想用javascript代碼更改收音機組。我有這樣的:如何用javascript代碼更改jquery移動單選按鈕組?

   <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"); 

,但它不工作...有誰知道什麼是錯?它在輸入標籤上放置了一個checked屬性。

感謝

回答

1

.attr()是指在實際標記的HTML屬性。你想要使用的不是HTML屬性,而是元素的DOM屬性。你需要.prop('checked')而不是.attr('checked')

1

當前複選框狀態不是它的attr,這是一個prop

all.prop("checked", false); 

應該工作。

相關問題