我试着在用户控件中用JQuery客户端检查CheckBoxList中的特定项目?
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AppCon %>"
SelectCommand="SELECT DesF, val, DesGrpId FROM dbo.tblDes WHERE (DesGrpId = @DesGrpId)">
</asp:SqlDataSource>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" DataTextField="DesF" DataValueField="val"
DataSourceID="SqlDataSource1">
发布于 2013-09-07 18:48:05
服务器端控制:
<asp:CheckBoxList ID="ChkList" runat="server">
<asp:ListItem Text ="a" Value="1"></asp:ListItem>
<asp:ListItem Text ="b" Value="2"></asp:ListItem>
<asp:ListItem Text ="c" Value="3"></asp:ListItem>
</asp:CheckBoxList>客户端代码:
<script type="text/javascript">
$(function () {
var str = "1,2";
var list = $('#<%= ChkList.ClientID%> input');
list.each(function (index) {
item = $(this);
if (str.indexOf(item.val()) != -1) {
item.attr('checked', true);
}
});
});
</script>发布于 2013-09-07 18:05:19
您是否正在尝试使用jQuery获取所有选中的项目?如果是这样,只需使用
var checkedItems = $('#parentDivOfCheckBox').find('input:checked');https://stackoverflow.com/questions/18672040
复制相似问题