程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> 無刷新三級聯動

無刷新三級聯動

編輯:C#入門知識

  <script type="text/javascript">
        $(function () {
            $.ajax({
                type: "post",
                contentType: "application/json",
                url: "WebService1.asmx/GetListProvince",
                Data: "{}",
                success: function (result) {
                    var strDrop = '';
                    for (var i = 0; i < result.d.length; i++) {
                        strDrop += "<option value='" + result.d[i].provinceID + "' >" + result.d[i].provinceName + "</option>";
                    }
                    $('#Province').append(strDrop);
                }
            })


            $('#Province').change(function () {
                $('#City option:gt(0)').remove();
                $('#Area option:gt(0)').remove();
                $.ajax({
                    type: "post",
                    contentType: "application/json",
                    url: "WebService1.asmx/GetListCity",
                    data: "{Id:'" + $(this).val() + "'}",
                    success: function (result) {
                        var strCity = '';
                        for (var i = 0; i < result.d.length; i++) {
                            strCity += "<option value='" + result.d[i].cityID + "' >" + result.d[i].cityName + "</option>";
                        }
                        $('#City').append(strCity);
                    }
                })
            })


            $('#City').change(function () {
                $('#Area option:gt(0)').remove();
                $.ajax({
                    type: "post",
                    contentType: "application/json",
                    url: "WebService1.asmx/GetListArea",
                    data: "{Id:'" + $(this).val() + "'}",
                    success: function (result) {
                        var strArea = '';
                        for (var i = 0; i < result.d.length; i++) {
                            strArea += "<option value='" + result.d[i].areaID + "' >" + result.d[i].areaName + "</option>";
                        }
                        $('#Area').append(strArea);
                    }
                })
            })


        })
    </script>

 

 

 

<select id="Province">

       <option>--請選擇--</option>
    </select>省
    <select id="City">
       <option>--請選擇--</option>
    </select>市
    <select id="Area">
      <option>--請選擇--</option>

    </select>縣

 


WebService

 


      [WebMethod]
        public List<Model.province> GetListProvince()
        {
            BLL.province bll_Province = new BLL.province();
            List<Model.province> list = bll_Province.GetListModel();
            return list;
        }


        [WebMethod]
        public List<Model.city> GetListCity(string Id)
        {
            BLL.city bll_City = new BLL.city();
            List<Model.city> list = bll_City.GetListCity("father='"+Id+"'");
            return list;
        }


        [WebMethod]
        public List<Model.area> GetListArea(string Id)
        {
            BLL.area bll_area = new BLL.area();
            List<Model.area> list = bll_area.GetlistArea("father='" + Id + "'");
            return list;
        }


三層的方法同上一篇文章的三層相同

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved