zoukankan      html  css  js  c++  java
  • ajax 三级联动

     
     
    <select class="st" id="st1">
                    <option value="null">加载中...</option>
                </select>
                <select class="st" id="st2">
                    <option value="null">加载中...</option>
                </select>
                <select class="st" id="st3">
                    <option value="null">加载中...</option>
                </select>
    3个select
     
     
    <script type="text/javascript">
    
        statesload('1');
    
        function statesload(a) {
            if (a == "1") {
                $.ajax({
                    url: "ccc.ashx",
                    data: { "pcode": "0001" },
                    type: "post",
                    dataType: "json",
                    success: function (msg) {
                        $("#st1").html('');
                        for (i in msg) {
                            var str = "<option value='" + msg[i].code + "'>" + msg[i].name + "</option>";
                            $("#st1").append(str);
                        }
                        statesload('2');
                    },
                    beforeSend: function () {
                        $("#st1").html('');
                        $("#st1").append("<option value='null'>加载中...</option>");
                    }
                });
            }
            if (a == "2") {
                $.ajax({
                    url: "ccc.ashx",
                    data: { "pcode": $("#st1").val() },
                    type: "post",
                    dataType: "json",
                    success: function (msg) {
                        $("#st2").html('');
                        for (i in msg) {
                            var str = "<option value='" + msg[i].code + "'>" + msg[i].name + "</option>";
                            $("#st2").append(str);
                        }
                        statesload('3');
                    },
                    beforeSend: function () {
                        $("#st2").html('');
                        $("#st2").append("<option value='null'>加载中...</option>");
                    }
                });
            }
            if (a == "3") {
                $.ajax({
                    url: "ccc.ashx",
                    data: { "pcode": $("#st2").val() },
                    type: "post",
                    dataType: "json",
                    success: function (msg) {
                        $("#st3").html('');
                        for (i in msg) {
                            var str = "<option value='" + msg[i].code + "'>" + msg[i].name + "</option>";
                            $("#st3").append(str);
                        }
                    },
                    beforeSend: function () {
                        $("#st3").html('');
                        $("#st3").append("<option value='null'>加载中...</option>");
                    }
                });
            }
    
        }
    
        $("#st1").change(function () {
            statesload('2');
        });
        $("#st2").change(function () {
            statesload('3');
        });
    
    </script>
    jquery

    后台

    public void ProcessRequest(HttpContext context)
        {
            System.Threading.Thread.Sleep(2000);
            StringBuilder str = new StringBuilder();
            str.Append("[");
            string s = context.Request["pcode"];
            using (mydbDataContext con = new mydbDataContext())
            {
                int count = 0;
                List<ChinaStates> clist = con.ChinaStates.Where(r => r.ParentAreaCode == s).ToList();
                foreach (ChinaStates c in clist)
                {
                    if (count > 0) str.Append(",");
                    str.Append("{"code":"" + c.AreaCode + "","name":"" + c.AreaName + ""}");
                    count++;
                }
            }
            str.Append("]");
            context.Response.Write(str);
            context.Response.End();
        }
    View Code
  • 相关阅读:
    解决"Windows没有足够信息,不能验证该证书"问题
    IPA 安装
    基于ECharts图表实现的股票K线图表(matols.com)
    WPF Chart
    IdentityServer4 中文文档
    企业信息系统
    手机网站的几点注意
    查询 SQL_Server 所有表的记录数: for xml path
    iframe在ipad safari的显示
    从WEB SERVICE 上返回大数据量的DATASET
  • 原文地址:https://www.cnblogs.com/v587yy/p/6957757.html
Copyright © 2011-2022 走看看