ajax 三級聯動

來源:互聯網
上載者:User

標籤:uil   聯動   UI   oid   one   script   state   builder   url   

  
<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

 

ajax 三級聯動

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.