本文章系Jarvis原創 轉載請注明!
    手頭做的項目中需要用到地區庫,在網上找了幾個地區庫,感覺不是很好,于是著手自己生成一個地區庫.地區來自中國統計局網站(數據夠官方)(地址是: http://www.stats.gov.cn/tjbz/xzqhdm/t20080215_402462675.htm),通過文本處理,生成到數據庫(需要該地區數據庫的朋友可留下郵箱地址,我發給你),做可處理操作. 
    這次用到的聯動是生成了一個地區的js文件,原來是采用AJAX實現聯動的,后來感覺生成JS文件并不大,所以采用js方式.
    下面是js處理代碼(基于JQuery):
<script type="text/javascript">
        $(document).ready(
function(){
            getProvinces();
        }
);
        
        
function getProvinces(){
            
var pro = "";
            
for(var i = 0 ; i < provinces.length; i++){
                pro 
+= "<option>" + provinces[i] + "</option>";
            }

            $('#province').empty().append(pro);
            getCities();
        }

        
function getCities(){
            
var proIndex = $('#province').attr('selectedIndex');
            showCities(proIndex);
            getCounties();
        }

        
function showCities(proIndex){
            
var cit = "";
            
if(cities[proIndex] == null){
                $('#city').empty();
                
return;
            }

            
for(var i = 0 ;i < cities[proIndex].length ; i++){
                cit 
+= "<option>" + cities[proIndex][i] + "</option>";
            }

            $('#city').empty().append(cit);
        }

        
function getCounties(){
            
var proIndex = $('#province').attr('selectedIndex');
            
var citIndex = $('#city').attr('selectedIndex');
            showCounties(proIndex,citIndex);
        }

        
function showCounties(proIndex,citIndex){
            
var cou = "";
            
if(counties[proIndex][citIndex] == null){
                $('#county').empty();
                
return;
            }

            
for(var i = 0 ;i < counties[proIndex][citIndex].length;i++){
                cou 
+= "<option>" + counties[proIndex][citIndex][i] + "</option>";
            }

            $('#county').empty().append(cou);
        }

        
</script>
<select id="province" onchange="getCities()"></select>
                    
<select id="city" onchange="getCounties()" style="width:120px;"></select>
                    
<select id="county" style="width:120px;"></select>
    這樣實現了一個比較好的地區聯動.
    歡迎大家討論.
    地區Js文件下載: /Files/qchong/area.rar