The descendant of the dragon -- xml_javascript three-level linkage

Source: Internet
Author: User
Currently, the third-level connections seen on the Internet are generally connected to databases or, using JavaScript Arrays for third-level linkages. I don't think this is necessary for data. It seems a bit cool and inconvenient to modify. Javascript arrays are not so easy to understand for beginners and are not easy to modify. XML is a good choice. It is very convenient to add and delete the arrays!
Provincecity. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Root>
<Province name = "Beijing" id = "110000">
<City name = "city jurisdiction" id = "110100">
<Area name = "Dongcheng District" id = "110101"/>
<Area name = "Xicheng district" id = "110102"/>
<Area name = "Chongwen District" id = "110103"/>
<Area name = "Xuanwu District" id = "110104"/>
<Area name = "Chaoyang District" id = "110105"/>
<Area name = "Fengtai District" id = "110106"/>
<Area name = "Shijingshan district" id = "110107"/>
<Area name = "Haidian District" id = "110108"/>
<Area name = "Mentougou District" id = "110109"/>
<Area name = "Fangshan District" id = "110111"/>
<Area name = "Tongzhou District" id = "110112"/>
<Area name = "Shunyi District" id = "110113"/>
<Area name = "Changping District" id = "110114"/>
<Area name = "Daxing District" id = "110115"/>
<Area name = "Huairou district" id = "110116"/>
<Area name = "Pinggu district" id = "110117"/>
</City>
<City name = "County" id = "110200">
<Area name = "Miyun county" id = "110228"/>
<Area name = "Yanqing County" id = "110229"/>
</City>
</Province>
<Province name = "Tianjin" id = "120000">
<City name = "city jurisdiction" id = "120100">
<Area name = "Heping District" id = "120101"/>
<Area name = "Hedong district" id = "120102"/>
<Area name = "Hexi District" id = "120103"/>
<Area name = "Nankai district" id = "120104"/>
<Area name = "Hebei District" id = "120105"/>
<Area name = "Hongqiao district" id = "120106"/>
<Area name = "Tanggu District" id = "120107"/>
<Area name = "hanggu district" id = "120108"/>
<Area name = "Dagang district" id = "120109"/>
<Area name = "dongli district" id = "120110"/>
<Area name = "Xiqing district" id = "120111"/>
<Area name = "Jinnan District" id = "120112"/>
<Area name = "Beichen District" id = "120113"/>
<Area name = "Wuqing district" id = "120114"/>
<Area name = "baodi district" id = "120115"/>
</City>
<City name = "County" id = "120200">
<Area name = "Ninghe county" id = "120221"/>
<Area name = "Jinghai County" id = "120223"/>
<Area name = "Ji Xian" id = "120225"/>
</City>
..........
........
........
</Province>
<Root>
<Script language = "JavaScript" type = "text/JavaScript">
VaR xmldoc;
VaR nodeindex;
Function getxmldoc ()
{
Xmldoc = new activexobject ("Microsoft. xmldom ");
VaR currnode;
Xmldoc. async = false;
Xmldoc. Load ("provincecity. xml ");
If (xmldoc. parseerror. errorcode! = 0)
{
VaR myerr = xmldoc. parseerror;
Alert ("error! "+ Myerr. Reason );
}
Getprovince1 ();
}
Function getprovince1 ()
{
VaR nodelist = xmldoc. selectsinglenode ("root"). childnodes;
VaR dropelement = Document. getelementbyid ("select1 ");
For (VAR I = 0; I <nodelist. length; I ++)
{
VaR provincenode = nodelist [I];
VaR eoption = Document. createelement ("option ");
Eoption. value = provincenode. getattribute ("ID ");
Eoption. Text = provincenode. getattribute ("name ");
Dropelement. Add (eoption );
}
}
Function selectcity1 ()
{
VaR dropelement = Document. getelementbyid ("select1 ");
VaR id = dropelement. Options [dropelement. selectedindex]. value;
VaR provincenode = xmldoc. selectsinglenode ("// root/province [@ ID =" + ID + "]");
VaR city = Document. getelementbyid ("select2 ");
VaR area = Document. getelementbyid ("select3 ");
Removedropdownlist (city );
Removedropdownlist (area );
For (VAR I = 0; I <provincenode. childnodes. length; I ++)
{
VaR citynode = provincenode. childnodes [I];
VaR eoption = Document. createelement ("option ");
Eoption. value = citynode. getattribute ("ID ");
Eoption. Text = citynode. getattribute ("name ");
City. Add (eoption );
}
}
Function selectarea1 ()
{
VaR dropelement = Document. getelementbyid ("select2 ");
VaR id = dropelement. Options [dropelement. selectedindex]. value;
VaR provincenode = xmldoc. selectsinglenode ("// root/province/City [@ ID =" + ID + "]");
VaR area = Document. getelementbyid ("select3 ");
Removedropdownlist (area );
For (VAR I = 0; I <provincenode. childnodes. length; I ++)
{
VaR citynode = provincenode. childnodes [I];
VaR eoption = Document. createelement ("option ");
Eoption. value = citynode. getattribute ("ID ");
Eoption. Text = citynode. getattribute ("name ");
Area. Add (eoption );
}
}
Function removedropdownlist (OBJ)
{
VaR Len = obj. Options. length;
// Alert (LEN );
For (VAR I = Len; I> = 0; I --)
{
OBJ. Remove (I );
}

}
</SCRIPT>
Demo: http://home.goofar.com/lkc311/XmlDropDownlist.htm
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.