Code
1
2<html xmlns="http://www.w3.org/1999/xhtml">
3
4<head>
5 <title>test</title>
6 <script>
7 var arr1="江西|福建";
8 var arr2=new Array();
9
10 arr2[0]="上饶|南昌|抚州";
11 arr2[1]="厦门|泉州";
12
13 var arr3=new Array;
14 arr3["上饶"]="万年|波阳";
15 arr3["南昌"]="南昌火车站|南昌大学";
16 arr3["厦门"]="思明|湖里";
17 arr3["泉州"]="晋江|水头";
18 var j=0;
19 var count=0;
20 function fun()
21 {
22 var one=arr1.split("|");
23 var sel1=document.getElementById("one1");
24 var sel2=document.getElementById("two2");
25 var sel3=document.getElementById("three3");
26 clearSel(sel1);
27 for(var i=0;i<one.length;i++)
28 {
29 sel1.options.add(new Option(one[i],one[i]));
30 }
31 var two=arr2[0].split("|");
32 clearSel(sel2);
33 for(var i=0;i<two.length;i++)
34 {
35 sel2.options.add(new Option(two[i],two[i]));
36 }
37 var three=arr3["上饶"].split("|");
38 clearSel(sel3);
39 for(var i=0;i<three.length;i++)
40 {
41 sel3.options.add(new Option(three[i],three[i]));
42 }
43 }
44 function clearSel(obj)
45 {
46 obj.innerHTML="";
47 }
48 function change1(obj)
49 {
50 j=obj.selectedIndex;
51 var sel2=document.getElementById("two2");
52 var sel3=document.getElementById("three3");
53 var two=arr2[j].split("|");
54 clearSel(sel2);
55 clearSel(sel3);
56 for(var i=0;i<two.length;i++)
57 {
58 sel2.options.add(new Option(two[i],two[i]));
59 }
60 var v=arr3[sel2.value].split("|");
61 for(var m=0;m<v.length;m++)
62 {
63 sel3.options.add(new Option(v[m],v[m]));
64 }
65 }
66 function change2(obj)
67 {
68 var sel2=document.getElementById("two2");
69 var sel3=document.getElementById("three3");
70 clearSel(sel3);
71 if(arr3[sel2.value]!=null)
72 {
73 var v=arr3[sel2.value].split("|");
74
75 for(var m=0;m<v.length;m++)
76 {
77 sel3.options.add(new Option(v[m],v[m]));
78 }
79 }
80 else
81
82 {
83 sel3.options.add(new Option("没有值","没有值"));
84 }
85 }
86
87 </script>
88 <style>
89 select
90 {
91 width:100px;
92
93 }
94 </style>
95</head>
96<body onload="fun()">
97
98<select id="one1" onchange="change1(this)">
99
100</select><select id="two2" onchange="change2(this)" ></select><select id="three3"></select>
101</body>
102
103</html>
1
2<html xmlns="http://www.w3.org/1999/xhtml">
3
4<head>
5 <title>test</title>
6 <script>
7 var arr1="江西|福建";
8 var arr2=new Array();
9
10 arr2[0]="上饶|南昌|抚州";
11 arr2[1]="厦门|泉州";
12
13 var arr3=new Array;
14 arr3["上饶"]="万年|波阳";
15 arr3["南昌"]="南昌火车站|南昌大学";
16 arr3["厦门"]="思明|湖里";
17 arr3["泉州"]="晋江|水头";
18 var j=0;
19 var count=0;
20 function fun()
21 {
22 var one=arr1.split("|");
23 var sel1=document.getElementById("one1");
24 var sel2=document.getElementById("two2");
25 var sel3=document.getElementById("three3");
26 clearSel(sel1);
27 for(var i=0;i<one.length;i++)
28 {
29 sel1.options.add(new Option(one[i],one[i]));
30 }
31 var two=arr2[0].split("|");
32 clearSel(sel2);
33 for(var i=0;i<two.length;i++)
34 {
35 sel2.options.add(new Option(two[i],two[i]));
36 }
37 var three=arr3["上饶"].split("|");
38 clearSel(sel3);
39 for(var i=0;i<three.length;i++)
40 {
41 sel3.options.add(new Option(three[i],three[i]));
42 }
43 }
44 function clearSel(obj)
45 {
46 obj.innerHTML="";
47 }
48 function change1(obj)
49 {
50 j=obj.selectedIndex;
51 var sel2=document.getElementById("two2");
52 var sel3=document.getElementById("three3");
53 var two=arr2[j].split("|");
54 clearSel(sel2);
55 clearSel(sel3);
56 for(var i=0;i<two.length;i++)
57 {
58 sel2.options.add(new Option(two[i],two[i]));
59 }
60 var v=arr3[sel2.value].split("|");
61 for(var m=0;m<v.length;m++)
62 {
63 sel3.options.add(new Option(v[m],v[m]));
64 }
65 }
66 function change2(obj)
67 {
68 var sel2=document.getElementById("two2");
69 var sel3=document.getElementById("three3");
70 clearSel(sel3);
71 if(arr3[sel2.value]!=null)
72 {
73 var v=arr3[sel2.value].split("|");
74
75 for(var m=0;m<v.length;m++)
76 {
77 sel3.options.add(new Option(v[m],v[m]));
78 }
79 }
80 else
81
82 {
83 sel3.options.add(new Option("没有值","没有值"));
84 }
85 }
86
87 </script>
88 <style>
89 select
90 {
91 width:100px;
92
93 }
94 </style>
95</head>
96<body onload="fun()">
97
98<select id="one1" onchange="change1(this)">
99
100</select><select id="two2" onchange="change2(this)" ></select><select id="three3"></select>
101</body>
102
103</html>