我有一个奇怪的问题。我有一个单选按钮列表,当它被选中时,它会显示下面与所选项目相对应的 div。单选按钮列表上方是复选框列表。单选按钮单击事件可以正常工作,直到您从上面的复选框列表中选中一个框。从上面的复选框列表中选中一个项目后,它开始返回“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”。