This article is a mirror article of machine translation, please click here to jump to the original article.

View: 17984|Reply: 3

[Jquery] jquery uses ajax request database for provincial and municipal linkage

[Copy link]
Posted on 8/19/2015 9:09:49 PM | | |
Because it was the first time I did this effect, I slowly did it and found that I had written a lot of repetitive code.

There is no time to optimize now, let's make do with it, and finally attach the compressed package, including the database script.

In addition, the provincial and municipal linkage code written in pure js is attached

Use JS to realize the three-level linkage menu of provinces and cities
http://www.itsvse.com/thread-2072-1-1.html
(Source: Wuhan Software Engineering Vocational College)


  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PlaceInfo.aspx.cs" Inherits="AjaxDemo.PlaceInfo" %>

  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5.     <title></title>
  6.     <scrip去掉t src="scrip去掉ts/jquery-1.4.1.min.js" type="text/javascrip去掉t"></scrip去掉t>
  7.     <scrip去掉t type="text/javascrip去掉t">

  8.         //省方法
  9.         function sheng() {
  10.             var $sheng = $("#sheng option:selected").val();
  11.             $.ajax({
  12.                 url: "ajax3.aspx",
  13.                 type: "get",
  14.                 data: "test=x&sheng=" + $sheng,
  15.                 success: function (mesg) {
  16.                     $("#shi").empty();
  17.                     $("#shi").append(mesg);
  18.                     $("#shi option:eq(0)").attr("selected", "selected");
  19.                     var num = $("#shi option").length;
  20.                     if (num > 1) {
  21.                         $("#shi").show();
  22.                     } else {
  23.                         $("#shi").hide();
  24.                     }
  25.                     shi();
  26.                 }
  27.             });
  28.         };
  29.         //市方法
  30.         function shi() {
  31.             var $shi = $("#shi option:selected").val();
  32.             $.ajax({
  33.                 url: "ajax3.aspx",
  34.                 type: "get",
  35.                 data: "test=x&sheng=" + $shi,
  36.                 success: function (mesg) {
  37.                     $("#xian").empty();
  38.                     $("#xian").append(mesg);
  39.                     $("#xian option:eq(0)").attr("selected", "selected");
  40.                 }
  41.             });
  42.         }
  43.         $(function () {

  44.             $.ajax({
  45.                 url: "ajax3.aspx",
  46.                 type: "get",
  47.                 data: "",
  48.                 success: function (mesg) {
  49.                     $("#sheng").append(mesg);
  50.                     $("#sheng option:eq(0)").attr("selected", "selected");
  51.                     sheng();
  52.                     
  53.                 }
  54.             });
  55.             /**测试按钮**/
  56.             $(":button").click(function () {
  57.                 var $a = $("#sheng option:selected").val();
  58.                 alert($a);
  59.             });
  60.             //选中省
  61.             $("#sheng").change(function () {
  62.                 sheng();
  63.             });
  64.             //选中市
  65.             $("#shi").change(function () {
  66.                 shi();
  67.             });
  68.         });
  69.     </scrip去掉t>
  70. </head>
  71. <body>
  72.     <form id="form1" runat="server">
  73.     <div>
  74.         <select id="sheng"></select>
  75.         <select id="shi"></select>
  76.         <select id="xian"></select>
  77.         <input type="button" value="test" />   
  78.     </div>
  79.     </form>
  80. </body>
  81. </html>
Copy code
AjaxDemo.rar (196.62 KB, Number of downloads: 4)




Previous:Computer hard disk C5 warning, what to do
Next:jquery several common knowledge points
Posted on 8/21/2015 9:44:21 PM |
Let me add

SSLD.rar

185.49 KB, Download times: 6, Download credits: -1 prestige, -1 contribution

Posted on 8/22/2015 7:45:21 AM |

Very powerful!!
Posted on 8/22/2015 5:55:02 PM |
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com