Jquery 获取CheckBoxList 中选择的值和获取RadioButton 选中的状态
<tr>
<td class="td_text" style="width: 150px;">
工程承包内容:
</td>
<td colspan="3" style="width: 600px;">
<asp:CheckBoxList ID="chkGcnr" runat="server" Height="20px" class="{required:true,messages:{required:'请选择工程承包内容!'}}" Width="550px" RepeatDirection="Horizontal">
<asp:ListItem Value="ytgckc" ClassAtt="tab_zbb_htdj_kc.gcnr_ytgckc">岩土工程勘察</asp:ListItem>
<asp:ListItem Value="ytgcsj" ClassAtt="tab_zbb_htdj_kc.gcnr_ytgcsj">岩土工程设计</asp:ListItem>
<asp:ListItem Value="ytgccs" ClassAtt="tab_zbb_htdj_kc.gcnr_ytgccs">岩土工程测试、监测、检测
</asp:ListItem>
<asp:ListItem Value="ytgczx" ClassAtt="tab_zbb_htdj_kc.gcnr_ytgczx">岩土工程咨询、监理</asp:ListItem>
<asp:ListItem Value="swdzkc" ClassAtt="tab_zbb_htdj_kc.gcnr_swdzkc">水文地质勘察</asp:ListItem>
<asp:ListItem Value="gccl" ClassAtt="tab_zbb_htdj_kc.gcnr_gccl">工程测量
</asp:ListItem>
<asp:ListItem Value="ytgczl" ClassAtt="tab_zbb_htdj_kc.gcnr_ytgczl">岩土工程治理
</asp:ListItem>
<asp:ListItem Value="gczt" ClassAtt="tab_zbb_htdj_kc.gcnr_gczt">工程钻探
</asp:ListItem>
<asp:ListItem Value="gczj" ClassAtt="tab_zbb_htdj_kc.gcnr_zj">凿井
</asp:ListItem>
</asp:CheckBoxList>
</td>
</tr>
获取函数
var gcnrtext = "";
$("#<%=chkGcnr.ClientID%> span").each(function (string) {
if ($(this).children().eq(0).is(':checked') == true) {
gcnrtext = gcnrtext + $(this).children().eq(1).text() + ";";
}
});
恶心变态的问题来了
CheckBoxList 初次加载带有span标签可以取到值, 第二次生成就没有span标签
所以此方法修改后为:
$("#<%=chkGcnr.ClientID%> input").each(function (string) {
if ($(this).is(':checked') == true) {
gcnrtext = gcnrtext + $(this).parent().find("label").text() + ";";
}
});
<asp:RadioButton ID="rdoCk" runat="server" Text="初勘" GroupName="rdo" />
<asp:RadioButton ID="rdoXk" runat="server" Text="详勘" GroupName="rdo" />
if (document.getElementById("<%=rdoCk.ClientID%>").checked == true )