JS製作的簡單的三級及聯

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   color   os   sp   java   

前台:

<form id="form1" runat="server">        <div>            省        <select id="Province">            <option>請選擇</option>        </select>            市        <select id="City">             <option>請選擇</option>        </select>            地區        <select id="Space">             <option>請選擇</option>        </select>           <script type="text/javascript">               $(function () {                   $.ajax({                       url: "TestClass/Cascade.ashx?id=1",                       async: false,                       success: function (data) {                           $("#Province").append(data);                           $("#Province").change(function () {                               $.ajax({                                   url: "TestClass/Cascade.ashx?id=2",                                   data: { pid: $("#Province").attr("value") },                                   success: function (data) {                                       $("#City").html("");                                       $("#City").append(data);                                       $("#City").change(                                           function () {                                               $.ajax({                                                   url: "TestClass/Cascade.ashx?id=3",                                                   data: { cid: $("#City").attr("value") },                                                   success: function (data) {                                                       $("#Space").html("");                                                       $("#Space").append(data);                                                   }                                               })                                           })                                   }                               })                           })                       }                   })               })            </script>        </div>    </form>

後台:

  public void ProcessRequest(HttpContext context)        {            context.Response.ContentType = "text/plain";            if (context.Request.QueryString["id"] == "1")            {                string sql = "SELECT ID,[enname] FROM [ProvinceInfo] WHERE ParentId=0";                StringBuilder sb = new StringBuilder();                SqlDataReader reader = PubSqlHelperFunc.ExecuteSqlDataReader(CommandType.Text, sql, null);                while (reader.Read())                {                    sb.Append("<option value=");                    sb.Append(reader["Id"]);                    sb.Append(">");                    sb.Append(reader["enname"]);                    sb.Append("</option>");                }                reader.Close();                context.Response.Write(sb.ToString());            }            else if (context.Request.QueryString["id"] == "2")            {                string sql = "SELECT ID,[enname] FROM [ProvinceInfo] WHERE ParentId=" + context.Request.Params["pid"] + "";                StringBuilder sb = new StringBuilder();                sb.Append("<option>請選擇</option>");                SqlDataReader reader = PubSqlHelperFunc.ExecuteSqlDataReader(CommandType.Text, sql, null);                while (reader.Read())                {                    sb.Append("<option value=");                    sb.Append(reader["Id"]);                    sb.Append(">");                    sb.Append(reader["enname"]);                    sb.Append("</option>");                }                reader.Close();                context.Response.Write(sb.ToString());            }            else if (context.Request.QueryString["id"] == "3")            {                string sql = "SELECT ID,[enname] FROM [ProvinceInfo] WHERE ParentId=" + context.Request.Params["cid"] + "";                StringBuilder sb = new StringBuilder();                sb.Append("<option>請選擇</option>");                SqlDataReader reader = PubSqlHelperFunc.ExecuteSqlDataReader(CommandType.Text, sql, null);                while (reader.Read())                {                    sb.Append("<option value=");                    sb.Append(reader["Id"]);                    sb.Append(">");                    sb.Append(reader["enname"]);                    sb.Append("</option>");                }                reader.Close();                context.Response.Write(sb.ToString());            }        }

 

JS製作的簡單的三級及聯

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.