Java JSON provincial cascade

Source: Internet
Author: User

Get information about the provinces and cities of China
$ (document). Ready (function () {

Get JSON-formatted data from a program
var info = $request. getattribute ("Manualorderareainfo");


var provinceinfo = $ ("#provinceId");
var Cityid = $ ("#cityId");

Clear information
Provinceinfo.empty ();

Loop to get information
$.each (Info.area, function (Idx,item) {
if (idx = = 0) {
return true;
}
Alert ("Name:" +idx+ ", Areaid:" +item.areaid+ ", AreaName:" +item.areaname+ ", Areaparentid:" +item.parentid ");

Here the parent class ID 1 is the city information
if (Item.parentid = = 1) {
$ ("<option value=" +item.areaid+ ">" +item.areaname+ "</option>"). AppendTo (Provinceinfo);
}
});
Get the city information
$ ("#provinceId"). Change (function () {
var tempinfo = $ ("#provinceId"). Val ();
Cityid.empty ();
$.each (Info.area, function (Indexinfo,item) {
if (Indexinfo = = 0) {
return true;
}
if (Item.parentid = = Tempinfo) {
$ ("<option value=" +item.areaid+ ">" +item.areaname+ "</option>"). AppendTo (Cityid);
}
});
});
});

Java JSON provincial cascade

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.