我有三個單選按鈕,在加載時可能會選擇其中一個按鈕。如果選擇2的值,我需要顯示一個div,如果其他兩個div應該隱藏。如果收音機沒有被選中,隱藏jquery負載div
單擊功能是否工作正常,但如果在頁面加載時它仍然顯示即使無線電沒有選擇
$("input[name='AssignmentType']").click(function() {
if ($(this).val() == 2) {
$('#selection').show();
} else {
$('#selection').hide(); /* If you want to be hidden if it's not */
}
});
HTML
<div class="col-md-10">
<div>
<input checked="checked" data-val="true" data-val-number="The field AssignmentType must be a number." htmlattributes="{ checked = True, class = form-control, id = AllCodes }" id="AssignmentType" name="AssignmentType" type="radio" value="0">
Available for All Employees
</div>
<div>
<input htmlattributes="{ checked = True, class = form-control, id = EEClass }" id="AssignmentType" name="AssignmentType" type="radio" value="1">
Available only to Employees in Class
</div>
<div>
<input htmlattributes="{ checked = True, class = form-control, id = EECombo }" id="AssignmentType" name="AssignmentType" type="radio" value="2">
Available for All Employees in combination of below Department, Position, State
</div>
</div>
嘿,請不要't撰寫[問題](http://stackoverflow.com/questions/32148185/show-css-hidden-div-on-load-using-jquery#32148185),編輯它們而不是刪除和問一個新的問題。 – Teemu
我不知道這是什麼意思 – TheDizzle
你應該給你的jQuery一些HTML,你可以再展示一些嗎? – Michelangelo