我有一個奇怪的問題。我有一個單選按鈕列表,當它被選中時,它會顯示下面對應選定項目的div。單選按鈕列表上方是複選框列表。單選按鈕單擊事件正常工作,直到您從上面的複選框列表中選中一個框。一旦從上面的複選框列表中檢查了一個項目,它就會開始返回「on」而不是所選單選按鈕的值。任何想法?jQuery RadioButtonList檢查值返回「on」
的jQuery:
<script type="text/javascript">
function CheckAllTrucks(sendingcb) {
$("#divTruckList :checkbox").prop("checked", $(sendingcb).prop("checked"));
}
function SetTimeframeInput(sendingrbl) {
var value = $(sendingrbl + ":checked").val();
$("#divTimeFrameControls .timeframectrls").each(function() {
$(this).hide();
});
$("#div" + value).show();
}
HTML/ASP.NET代碼:
<div class="form-field">
<asp:CheckBox ID="cbSelectAllTrucks" runat="server" Text="Select All Trucks" onclick="CheckAllTrucks(this)" />
<div id="divTruckList">
<asp:CheckBoxList ID="cblTrucks" runat="server" />
</div>
</div>
<div class="form-field">
<asp:RadioButtonList ID="rblTimeFrame" runat="server" onclick="SetTimeframeInput(this)">
<asp:ListItem Text="Month" Value="month" />
<asp:ListItem Text="Quarter" Value="quarter" />
<asp:ListItem Text="January-December" Value="jandec" />
<asp:ListItem Text="July-June" Value="juljun" />
</asp:RadioButtonList>
<div id="divTimeFrameControls">
<div id="divmonth" class="timeframectrls" style="display: none;">
<!-- month fields -->
</div>
<div id="divquarter" class="timeframectrls" style="display: none;">
<!-- quarter fields -->
</div>
<div id="divjandec" class="timeframectrls" style="display: none;">
<!-- jandec fields -->
</div>
<div id="divjuljun" class="timeframectrls" style="display: none;">
<!-- juljun fields -->
</div>
</div>
</div>
提前感謝!
編輯
我發現這個只有當一個複選框檢查情況。如果您檢查並取消選中,則該值仍然正確。只有當複選框被選中時,它纔會將值設置爲「on」。
你知道,你可以將你的問題標記爲答案:) – Jashwant
它不會讓我將自己的答案標記爲2天的答案。 – Ricketts