jQuery获取checkboxlist选中值

如图1所示,从留学国家中选中需要的留学国家,选中顾问触发事件,获取选中的留学国家,如果留学国家为空,提示留学国家不为空
这里写图片描述
图1
前台页面代码如下

InputStudy.aspx

 <div class="row" id="panelAbroad1" runat="server">
                        <div class="span12">
                            <div class="input-group">
                                <span class="input-group-addon ie_widthauto">留学国家:<font color="red">*</font></span>
                                <asp:CheckBoxList ID="ckkHopeCountryList"  CssClass="checkbox-inline form-control ie_widthauto checkboxlist "  runat="server" RepeatDirection="Horizontal" RepeatColumns="12">
                                </asp:CheckBoxList>
                            </div>
                        </div>
                    </div>
<div class="row" id="panelACouslt1" runat="server">
                        <div class="span5">
                            <div class="input-group">
                                <span class="input-group-addon ie_widthauto">顾问:<font color="red">*</font></span>
                                <select id="dllRecordDepList" name="dllRecordDepList" class="form-control ie_widthauto" runat="server">
                                    <option value="-1">无咨询员</option>
                                </select>
                                <input type="hidden" id="hidRecDep" runat="server" />
                                <input type="hidden" id="hidAConsultant" runat="server" />
                                <span class="input-group-addon ie_widthauto">-></span>
                                <select name="selAConsultant" id="selAConsultant" class="form-control ie_widthauto" runat="server">
                                    <option value="-1">--请选择-- </option>
                                </select>
                            </div>
                        </div>

                    </div>

后台绑定checkboxlist数据,用的ORM
inputStudy.aspx.cs

 /// <summary>
        /// 留学国家
        /// </summary>
        private IList GetHopeCountryList(int GroupID)
        {
            IList RecepList = new ArrayList();
            IDataReader rdr;
            if (GroupID == 0)
            {
                rdr = DB.Context.FromSql("select CountryID,Country from tblRecepCountry where Flag=0").ToDataReader();
            }
            else
            {
                rdr = DB.Context.FromSql("select CountryID,Country from tblRecepCountry where Flag=0 and GroupID=@GroupID").AddInParameter("@GroupID", DbType.Int32, GroupID).ToDataReader();
            }
            while (rdr.Read())
            {
                Model.tblRecepCountry cyInfo = new Model.tblRecepCountry();
                cyInfo.CountryID = int.Parse(rdr["CountryID"].ToString());
                cyInfo.Country = rdr["Country"].ToString();
                RecepList.Add(cyInfo);
            }
            return RecepList;
        }

jQuery代码
ConsultantType02.js

 $(document).ready(function () {
 $("#dllRecordDepList").change(function () {
        var id = $(this).val();
        var country = "";
        $("input[name^='ckkHopeCountryList']").each(function () {
            if (this.checked) {
                country = country + $(this).next().text() + "*";
            }
        });
        if (country == "" || country == undefined) {
            alert("留学国家不能为空")
        } else {
            $.ajax({
                type: "POST",
                url: "../Handler/ConsultantType02.ashx",
                data: { type: "AConsultant", id: id, country: country },
                success: function (data) {
                    if (data == "fail") {
                        alert("loading failed");
                    }
                    else {
                        addAConsultantList(data);
                    }
                }
            });
        }
    });
  });

关键代码为

 var country = "";
        $("input[name^='ckkHopeCountryList']").each(function () {
            if (this.checked) {
                country = country + $(this).next().text() + "*";
            }
        });

通过F12观察checkboxlist生成的是一个table对应的name是ckkHopeCountryList
这里写图片描述
如果想了解ajax级联的写法可以点击下面的连接
http://blog.csdn.net/sunping177/article/details/51162820

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值