Jquery's method of reading xml files to achieve provincial/municipal/county-level linkage

Source: Internet
Author: User

Jquery's method of reading xml files to achieve provincial/municipal/county-level linkage

This example describes how jquery reads xml files to implement provincial/municipal/county-level linkage. Share it with you for your reference. The details are as follows:

The page code is as follows:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">

<Html>

<Head>

<Base href = "<% = basePath %>">

<Title> My JSP 'city. jsp 'starting page </title>

<Meta http-equiv = "pragma" content = "no-cache">

<Meta http-equiv = "cache-control" content = "no-cache">

<Meta http-equiv = "expires" content = "0">

<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">

<Meta http-equiv = "description" content = "This is my page">

<! --

<Link rel = "stylesheet" type = "text/css" href = "styles.css">

-->

<Script type = "text/javascript" src = "js/jquery-1.7.2.min.js"> </script>

<Script type = "text/javascript">

$ (Document). ready (function (){

// Save

$. Ajax ({url: "xml/City. xml ",

Success: function (xml ){

$ (Xml). find ("province"). each (function (){

Var t = $ (this). attr ("name"); // this->

$ ("# DropProvince"). append ("<option>" + t + "</option> ");

});

}

});

// City

$ ("# DropProvince"). change (function (){

$ ("# SCity> option"). remove ();

$ ("# SArea> option"). remove ();

Var pname = $ ("# DropProvince"). val ();

$. Ajax ({url: "xml/City. xml ",

Success: function (xml ){

/// Search for all the first-level child elements (that is, the city) under <province>)

$ (Xml). find ("province [name = '" + pname + "']> city"). each (function (){

Var city = $ (this). attr ("name"); // this->

$ ("# SCity"). append ("<option>" + city + "</option> ");

});

/// Search for all the first level child elements (that is, the region) under <city>)

Var cname = $ ("# sCity"). val ();

$ (Xml). find ("city [name = '" + cname + "']> area"). each (function (){

Var area = $ (this). attr ("name"); // this->

$ ("# SArea"). append ("<option>" + area + "</option> ");

});

}

});

});

// Zone

$ ("# SCity"). change (function (){

$ ("# SArea> option"). remove ();

Var cname = $ ("# sCity"). val ();

$. Ajax ({url: "xml/City. xml ",

Success: function (xml ){

/// Search for all the first level child elements (that is, the region) under <city>)

$ (Xml). find ("city [name = '" + cname + "']> area"). each (function (){

Var area = $ (this). attr ("name"); // this->

$ ("# SArea"). append ("<option>" + area + "</option> ");

});

}

});

});

});

</Script>

</Head>

<Body>

<Form id = "form1">

<Div>

<Select id = "DropProvince" style = "width: 100px;">

<Option> select </option>

</Select>

<Select id = "sCity" style = "width: 100px;">

<Option> select a city </option>

</Select>

<Select id = "sArea" style = "width: 100px;">

<Option> select a zone </option>

</Select>

</Div>

</Form>

</Body>

</Html>

As follows:

I hope this article will help you with jQuery programming.

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.