Ajax three-tier linkage provinces and cities choose to use jquery+html+xml__html

Source: Internet
Author: User

HTML code

 

Province_city.js Content

$ (function () {var address = $ ("#pro_city");
    var province = $ ("#province");
    var city = $ ("#city");
    var area = $ ("#area");
    var preprovince = "<option value=\" \ "> select Province (city) </option>";
    var precity = "<option value=\" \ "> select City (District) </option>";
    var Prearea = "<option value=\" \ "> select area (County) </option>";
    Province.html (preprovince);
    City.html (precity);
    Area.html (Prearea);
    $.ajax ({type: "Get", url: "/js/province_city_select/info.xml", Success:func_suc_getxmlprovice
    });
            Province.change (function () {if (Province.val ()!= "") {city.html (precity); $.ajax ({type: "Get", url: "/js/province_city_select/info.xml", success:f
            Unc_suc_getxmlcity});
        City.change ();
    }
    });
        City.change (function () {area.html (Prearea); $.ajax ({type: "Get", url: "/js/proVince_city_select/info.xml ", Success:func_suc_getxmlarea});
    }); Area.change (function () {var value = Province.find ("option:selected"). Text () + city.find ("option:selected"). Text (
        ) + Area.find ("option:selected"). Text ();
        Address.text (value);
    $ ("#txtProCity"). val (value);
    });
        function Func_suc_getxmlprovice (XML) {var Sheng = $ (XML). Find ("Prov"); Sheng.each (function (i) {province.append ("<option value=" + i + ">" + sheng.eq (i). attr ("text") + "</
        Option> ");
    });
        function Func_suc_getxmlcity (XML) {var Xml_sheng = $ (XML). Find ("Prov");
        var pro_num = parseint (Province.val ());
        var Xml_shi = Xml_sheng.eq (pro_num). Find ("City"); Xml_shi.each (function (j) {City.append ("<option value=" + j + ">" + Xml_shi.eq (j). attr ("text") + <
        /option> ");
    }); } function Func_suc_getxmlarea (XML) {var Xml_sheng = $ (XML). Find ("Prov");
        var pro_num = parseint (Province.val ());
        var Xml_shi = Xml_sheng.eq (pro_num). Find ("City");
        var city_num = parseint (City.val ());
        var xml_xianqu = Xml_shi.eq (city_num). Find ("county");  Xml_xianqu.each (function (k) {area.append ("<option value=" + k + ">" + Xml_xianqu.eq (k). attr ("text") +
        "</option>");
    });
 }
});

Info.xml content is a list of Chinese provinces and cities, a bit large, full version here to download

http://download.csdn.net/detail/ful1021/6555541

Or leave a mailbox to send

<?xml version= "1.0" encoding= "gb2312"?> <district> <prov id= "110000" text= "Beijing" > <city id= "110100 "text=" Municipal > <county id= "110101" text= "Dongcheng District" ></county> <county id= "110102" text= "Xicheng District" ></coun
			ty> <county id= "110103" text= "Chongwen District" ></county> <county id= "110104" text= "Xuan Wu" ></county>  <county id= "110105" text= "Chaoyang District" ></county> <county id= "110106" text= "Fengtai District" ></county> <county Id= "110107" text= "Shijingshan District" ></county> <county id= "110108" text= "Haidian" ></county> <county id= "1101 "Text=" Mentougou District ></county> <county id= "110111" text= "Fangshan District" ></county> <county id= "110112" text= "Tongzhou District" ></county> <county id= "110113" text= "Shunyi District" ></county> <county id= "110114" text= "Changping District" >& lt;/county> <county id= "110115" text= "Daxing District" ></county> <county id= "110116" text= "Huairou" ></county > <county id= "110117 "text=" Pinggu District "></county> </city> <city id=" 110200 "text=" counties "> <county id=" 110228 "text=" Miyun County "></county> <county id=" 110229 "text=" Yanqing County "></county> </city> </prov> </district >




Cloud Blog: www.yuntianseo.com focus on Network marketing promotion

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.