commit | author | age
|
19351a
|
1 |
/* $Id : region.js 4865 2007-01-31 14:04:10Z paulgao $ */ |
B |
2 |
|
|
3 |
var region = new Object(); |
|
4 |
|
|
5 |
region.isAdmin = false; |
|
6 |
|
|
7 |
region.loadRegions = function(parent, type, target) |
|
8 |
{ |
|
9 |
Ajax.call(region.getFileName(), 'type=' + type + '&target=' + target + "&parent=" + parent , region.response, "GET", "JSON"); |
|
10 |
} |
|
11 |
|
|
12 |
/* * |
|
13 |
* 载入指定的国家下所有的省份 |
|
14 |
* |
|
15 |
* @country integer 国家的编号 |
|
16 |
* @selName string 列表框的名称 |
|
17 |
*/ |
|
18 |
region.loadProvinces = function(country, selName) |
|
19 |
{ |
|
20 |
var objName = (typeof selName == "undefined") ? "selProvinces" : selName; |
|
21 |
|
|
22 |
region.loadRegions(country, 1, objName); |
|
23 |
} |
|
24 |
|
|
25 |
/* * |
|
26 |
* 载入指定的省份下所有的城市 |
|
27 |
* |
|
28 |
* @province integer 省份的编号 |
|
29 |
* @selName string 列表框的名称 |
|
30 |
*/ |
|
31 |
region.loadCities = function(province, selName) |
|
32 |
{ |
|
33 |
var objName = (typeof selName == "undefined") ? "selCities" : selName; |
|
34 |
|
|
35 |
region.loadRegions(province, 2, objName); |
|
36 |
} |
|
37 |
|
|
38 |
/* * |
|
39 |
* 载入指定的城市下的区 / 县 |
|
40 |
* |
|
41 |
* @city integer 城市的编号 |
|
42 |
* @selName string 列表框的名称 |
|
43 |
*/ |
|
44 |
region.loadDistricts = function(city, selName) |
|
45 |
{ |
|
46 |
var objName = (typeof selName == "undefined") ? "selDistricts" : selName; |
|
47 |
|
|
48 |
region.loadRegions(city, 3, objName); |
|
49 |
} |
|
50 |
|
|
51 |
/* * |
|
52 |
* 处理下拉列表改变的函数 |
|
53 |
* |
|
54 |
* @obj object 下拉列表 |
|
55 |
* @type integer 类型 |
|
56 |
* @selName string 目标列表框的名称 |
|
57 |
*/ |
|
58 |
region.changed = function(obj, type, selName) |
|
59 |
{ |
|
60 |
var parent = obj.options[obj.selectedIndex].value; |
|
61 |
|
|
62 |
region.loadRegions(parent, type, selName); |
|
63 |
} |
|
64 |
|
|
65 |
region.response = function(result, text_result) |
|
66 |
{ |
|
67 |
var sel = document.getElementById(result.target); |
|
68 |
|
|
69 |
sel.length = 1; |
|
70 |
sel.selectedIndex = 0; |
|
71 |
sel.style.display = (result.regions.length == 0 && ! region.isAdmin && result.type + 0 == 3) ? "none" : ''; |
|
72 |
|
|
73 |
if (document.all) |
|
74 |
{ |
|
75 |
sel.fireEvent("onchange"); |
|
76 |
} |
|
77 |
else |
|
78 |
{ |
|
79 |
var evt = document.createEvent("HTMLEvents"); |
|
80 |
evt.initEvent('change', true, true); |
|
81 |
sel.dispatchEvent(evt); |
|
82 |
} |
|
83 |
|
|
84 |
if (result.regions) |
|
85 |
{ |
|
86 |
for (i = 0; i < result.regions.length; i ++ ) |
|
87 |
{ |
|
88 |
var opt = document.createElement("OPTION"); |
|
89 |
opt.value = result.regions[i].region_id; |
|
90 |
opt.text = result.regions[i].region_name; |
|
91 |
|
|
92 |
sel.options.add(opt); |
|
93 |
} |
|
94 |
} |
|
95 |
} |
|
96 |
|
|
97 |
region.getFileName = function() |
|
98 |
{ |
|
99 |
if (region.isAdmin) |
|
100 |
{ |
|
101 |
return "../region.php"; |
|
102 |
} |
|
103 |
else |
|
104 |
{ |
|
105 |
return "region.php"; |
|
106 |
} |
|
107 |
} |