1 JSP部分代码
2
3
4
5 <script src="/js/jquery-1.2.6.min.js" type="text/javascript"></script>
6 <script>
7 //为了避免jquery中的'$'与其它的'$'冲突,在此将jquery中的'$'重命名为'jQuery'
8 var jQuery=$;
9 </script>
10
11
12
13
14 <script>
15
16
17 //初始化数据
18 jQuery(document).ready(function(){
19
20 getProvince();
21
22 });
23
24
25
26
27 //取所有省份
28 function getProvince(){
29
30 //&callback=?"注意这个是为了解决跨域访问的问题
31 var url ="http://www.yimei.com/shopcar/getAreaJSON?areaId=0&callback=?";
32
33 jQuery.getJSON(url,null,function call(result){
34 setProvince(result);
35 });
36
37 //显示或隐藏激活卡
38 jQuery("#actionCardChk").click(function(){
39 if(jQuery("#actionCardChk").attr("checked")==true){
40 jQuery("#actionCardDiv").show();
41 }else{
42 jQuery("#actionCardDiv").hide();
43 }
44 });
45
46 //显示或隐藏新增常用地址
47 jQuery("#addressChk").click(function(){
48 if(jQuery("#addressChk").attr("checked")==true){
49 jQuery("#addressDiv").show();
50 }else{
51 jQuery("#addressDiv").hide();
52 }
53 });
54
55
56 }
57
58
59
60
61 //设置省份
62 function setProvince(result){
63
64 var province = document.getElementById("toProvince");
65
66 jQuery.each(result.data, function(i, area){
67 var value = area.id;
68 var text = area.name;
69 var option = new Option(text,value);
70 province.options.add(option);
71
72 });
73
74 }
75
76
77 //按上级ID取子地区
78 function getArea(name){
79
80 if( name=='city' ){
81 clearSel(document.getElementById("toCity")); //清空城市
82 var province = document.getElementById("toProvince");
83 if(province.options[province.selectedIndex].value == "") return;
84 var areaId = province.options[province.selectedIndex].value;
85
86 var url ="http://www.yimei.com/shopcar/getAreaJSON?areaId="+areaId+"&callback=?";
87 jQuery.getJSON(url,null,function call(result){
88 setCity(result);
89 });
90
91 }else if( name=='county'){
92 clearSel(document.getElementById("toCounty")); //清空城区
93 var city = document.getElementById("toCity");
94 if(city.options[city.selectedIndex].value == "") return;
95 var areaId = city.options[city.selectedIndex].value;
96
97 var url ="http://www.yimei.com/shopcar/getAreaJSON?areaId="+areaId+"&callback=?";
98 jQuery.getJSON(url,null,function call(result){
99 setCounty(result);
100 });
101
102 }
103 }
104
105 //当改变省份时设置城市
106 function setCity(result){
107
108 var city = document.getElementById("toCity");
109
110 jQuery.each(result.data, function(i, area){
111 var value = area.id;
112 var text = area.name;
113 var option = new Option(text,value);
114 city.options.add(option);
115 });
116
117 }
118
119
120 //当改变省份时设置城市
121 function setCounty(result){
122
123 var county = document.getElementById("toCounty");
124
125 jQuery.each(result.data, function(i, area){
126 var value = area.id;
127 var text = area.name;
128 var option = new Option(text,value);
129 county.options.add(option);
130 });
131
132 }
133
134 // 清空下拉列表
135 function clearSel(oSelect){
136
137 while(oSelect.childNodes.length>0){
138 oSelect.removeChild(oSelect.childNodes[0]);
139 }
140
141 }
142
143
144
145 </script>
146
147
148
149 <tr>
150 <td height="28" colspan="3">
151 <select name="toProvince" >445 json-lib-2.1-jdk15.jar 是主要的
相关文章: