『壹』 javascript實現二級聯動,比如連個下拉列表,一個選擇省份,另一個自動出現相應城市
<script language=vbScript>
<!--
public x(33)
x( 0 )="東城,西城,崇文,宣武,朝陽,豐台,石景山,海淀,門頭溝,房山,通州,順義,昌平,大興,平谷,懷柔,密雲,延慶"
x( 1 )="黃浦,盧灣,徐匯,長寧,靜安,普陀,閘北,虹口,楊浦,閔行,寶山,嘉定,浦東,金山,松江,青浦,南匯,奉賢,崇明"
x( 2 )="和平,東麗,河東,西青,河西,津南,南開,北辰,河北,武清,紅撟,塘沽,漢沽,大港,寧河,靜海,寶坻,薊縣"
x( 3 )="萬州,涪陵,渝中,大渡口,江北,沙坪壩,九龍坡,南岸,北碚,萬盛,雙撟,渝北,巴南,黔江,長壽,綦江,潼南,銅梁,大足,榮昌,壁山,梁平,城口,豐都,墊江,武隆,忠縣,開縣,雲陽,奉節,巫山,巫溪,石柱,秀山,酉陽,彭水,江津,合川,永川,南川"
x( 4 )="石家莊,邯鄲,邢台,保定,張家口,承德,廊坊,唐山,秦皇島,滄州,衡水"
x( 5 )="太原,大同,陽泉,長治,晉城,朔州,呂梁,忻州,晉中,臨汾,運城"
x( 6 )="呼和浩特,包頭,烏海,赤峰,呼倫貝爾盟,阿拉善盟,哲里木盟,興安盟,烏蘭察布盟,錫林郭勒盟,巴彥淖爾盟,伊克昭盟"
x( 7 )="沈陽,大連,鞍山,撫順,本溪,丹東,錦州,營口,阜新,遼陽,盤錦,鐵嶺,朝陽,葫蘆島"
x( 8 )="長春,吉林,四平,遼源,通化,白山,松原,白城,延邊"
x( 9 )="哈爾濱,齊齊哈爾,牡丹江,佳木斯,大慶,綏化,鶴崗,雞西,黑河,雙鴨山,伊春,七台河,大興安嶺"
x( 10 )="南京,鎮江,蘇州,南通,揚州,鹽城,徐州,連雲港,常州,無錫,宿遷,泰州,淮安"
x( 11 )="杭州,寧波,溫州,嘉興,湖州,紹興,金華,衢州,舟山,台州,麗水"
x( 12 )="合肥,蕪湖,蚌埠,馬鞍山,淮北,銅陵,安慶,黃山,滁州,宿州,池州,淮南,巢湖,阜陽,六安,宣城,亳州"
x( 13 )="福州,廈門,莆田,三明,泉州,漳州,南平,龍岩,寧德"
x( 14 )="南昌市,景德鎮,九江,鷹潭,萍鄉,新餘,贛州,吉安,宜春,撫州,上饒"
x( 15 )="濟南,青島,淄博,棗庄,東營,煙台,濰坊,濟寧,泰安,威海,日照,萊蕪,臨沂,德州,聊城,濱州,菏澤"
x( 16 )="鄭州,開封,洛陽,平頂山,安陽,鶴壁,新鄉,焦作,濮陽,許昌,漯河,三門峽,南陽,商丘,信陽,周口,駐馬店,濟源"
x( 17 )="武漢,宜昌,荊州,襄樊,黃石,荊門,黃岡,十堰,恩施,潛江,天門,仙桃,隨州,咸寧,孝感,鄂州"
x( 18 )="長沙,常德,株洲,湘潭,衡陽,岳陽,邵陽,益陽,婁底,懷化,郴州,永州,湘西,張家界"
x( 19 )="廣州,深圳,珠海,汕頭,東莞,中山,佛山,韶關,江門,湛江,茂名,肇慶,惠州,梅州,汕尾,河源,陽江,清遠,潮州,揭陽,雲浮"
x( 20 )="南寧,柳州,桂林,梧州,北海,防城港,欽州,貴港,玉林,南寧地區,柳州地區,賀州,百色,河池"
x( 21 )="海口,三亞"
x( 22 )="成都,綿陽,德陽,自貢,攀枝花,廣元,內江,樂山,南充,宜賓,廣安,達川,雅安,眉山,甘孜,涼山,瀘州"
x( 23 )="貴陽,六盤水,遵義,安順,銅仁,黔西南,畢節,黔東南,黔南"
x( 24 )="昆明,大理,曲靖,玉溪,昭通,楚雄,紅河,文山,思茅,西雙版納,保山,德宏,麗江,怒江,迪慶,臨滄"
x( 25 )="拉薩,日喀則,山南,林芝,昌都,阿里,那曲"
x( 26 )="西安,寶雞,咸陽,銅川,渭南,延安,榆林,漢中,安康,商洛"
x( 27 )="蘭州,嘉峪關,金昌,白銀,天水,酒泉,張掖,武威,定西,隴南,平涼,慶陽,臨夏,甘南"
x( 28 )="銀川,石嘴山,吳忠,固原"
x( 29 )="西寧,海東,海南,海北,黃南,玉樹,果洛,海西"
x( 30 )="烏魯木齊,石河子,克拉瑪依,伊犁,巴音郭勒,昌吉,克孜勒蘇柯爾克孜,博 爾塔拉,吐魯番,哈密,喀什,和田,阿克蘇"
x( 31 )=""
x( 32 )=""
x( 33 )="台北,高雄,台中,台南,屏東,南投,雲林,新竹,彰化,苗栗,嘉義,花蓮,桃園,宜蘭,基隆,台東,金門,馬祖,澎湖"
function test(a,b)
dim num,x1,i
num =a.selectedIndex
x1=split(x(num),",")
b.options.length=ubound(x1)+1
For i = 0 to ubound(x1)
b.options(i).text =x1(i)
b.options(i).value = x1(i)
next
end function
-->
</script>
<body>
<select name="a" size=1 onChange="vbscript:test a,b">
<option value= 0 >北京</option>
<option value= 1 >上海</option>
<option value= 2 >天津</option>
<option value= 3 >重慶</option>
<option value= 4 >河北</option>
<option value= 5 >山西</option>
<option value= 6 >內蒙古</option>
<option value= 7 >遼寧</option>
<option value= 8 >吉林</option>
<option value= 9 >黑龍江</option>
<option value= 10 >江蘇</option>
<option value= 11 >浙江</option>
<option value= 12 >安徽</option>
<option value= 13 >福建</option>
<option value= 14 >江西</option>
<option value= 15 >山東</option>
<option value= 16 >河南</option>
<option value= 17 >湖北</option>
<option value= 18 >湖南</option>
<option value= 19 >廣東</option>
<option value= 20 >廣西</option>
<option value= 21 >海南</option>
<option value= 22 >四川</option>
<option value= 23 >貴州</option>
<option value= 24 >雲南</option>
<option value= 25 >西藏</option>
<option value= 26 >陝西</option>
<option value= 27 >甘肅</option>
<option value= 28 >寧夏</option>
<option value= 29 >青海</option>
<option value= 30 >新疆</option>
<option value= 31 >香港</option>
<option value= 32 >澳門</option>
<option value= 33 >台灣</option>
</select>
<select name="b">
</select>
拷貝到記事本.保存為.htm或.asp
『貳』 iOS開發,想知道國家氣象局api返回過來的天氣數據將天氣總共描述為幾種類型,
之前做過相關的App,網上搜出來的,直接粘貼了。有用請採納哦~
國家氣象局提供的天氣預報介面
介面地址:
http://www.weather.com.cn/data/sk/101010100.html
http://www.weather.com.cn/data/cityinfo/101010100.html
http://m.weather.com.cn/data/101010100.html
對於第三個介面,返回信息比較全面,也是以json格式提供,格式如下
{"weatherinfo": {//基本信息;"city":"北京","city_en":"beijing","date_y":"2012年2月16日", "date":"", "week":"星期四", "fchh":"11", "cityid":"101010100",//攝氏溫度"temp1":"2℃~-7℃","temp2":"1℃~-7℃","temp3":"4℃~-7℃","temp4":"7℃~-5℃","temp5":"5℃~-3℃","temp6":"5℃~-2℃",//華氏溫度;"tempF1":"35.6℉~19.4℉","tempF2":"33.8℉~19.4℉","tempF3":"39.2℉~19.4℉","tempF4":"44.6℉~23℉","tempF5":"41℉~26.6℉","tempF6":"41℉~28.4℉",//天氣描述;"weather1":"晴","weather2":"晴","weather3":"晴","weather4":"晴轉多雲","weather5":"多雲","weather6":"多雲轉陰",//天氣描述圖片序號"img1":"0","img2":"99","img3":"0","img4":"99","img5":"0","img6":"99","img7":"0","img8":"1","img9":"1","img10":"99","img11":"1","img12":"2","img_single":"0",//圖片名稱;"img_title1":"晴","img_title2":"晴","img_title3":"晴","img_title4":"晴","img_title5":"晴","img_title6":"晴","img_title7":"晴","img_title8":"多雲","img_title9":"多雲","img_title10":"多雲","img_title11":"多雲","img_title12":"陰","img_title_single":"晴",//風速描述"wind1":"北風3-4級轉微風","wind2":"微風","wind3":"微風","wind4":"微風","wind5":"微風","wind6":"微風",//風速級別描述"fx1":"北風","fx2":"微風","fl1":"3-4級轉小於3級","fl2":"小於3級","fl3":"小於3級","fl4":"小於3級","fl5":"小於3級","fl6":"小於3級",//今天穿衣指數;"index":"冷","index_d":"天氣冷,建議著棉衣、皮夾克加羊毛衫等冬季服裝。年老體弱者宜著厚棉衣或冬大衣。",//48小時穿衣指數"index48":"冷","index48_d":"天氣冷,建議著棉衣、皮夾克加羊毛衫等冬季服裝。年老體弱者宜著厚棉衣或冬大衣。",//紫外線及48小時紫外線"index_uv":"弱","index48_uv":"弱",//洗車"index_xc":"適宜",//旅遊"index_tr":"一般",//舒適指數"index_co":"較不舒適","st1":"1","st2":"-8","st3":"2","st4":"-4","st5":"5","st6":"-5",//晨練"index_cl":"較不宜",//晾曬"index_ls":"基本適宜",//過敏"index_ag":"極不易發"}}
全國各城市代碼如下:
北京:101010100朝陽:101010300順義:101010400懷柔:101010500通州:101010600昌平:101010700延慶:101010800豐台:101010900石景山:101011000大興:101011100房山:101011200密雲:101011300門頭溝:101011400平谷:101011500八達嶺:101011600佛爺頂:101011700湯河口:101011800密雲上甸子:101011900齋堂:101012000霞雲嶺:101012100北京城區:101012200海淀:101010200天津:101030100寶坻:101030300東麗:101030400西青:101030500北辰:101030600薊縣:101031400漢沽:101030800靜海:101030900津南:101031000塘沽:101031100大港:101031200武清:101030200寧河:101030700上海:101020100寶山:101020300嘉定:101020500南匯:101020600浦東:101021300青浦:101020800松江:101020900奉賢:101021000崇明:101021100徐家匯:101021200閔行:101020200金山:101020700石家莊:101090101張家口:101090301承德:101090402唐山:101090501秦皇島:101091101滄州:101090701衡水:101090801邢台:101090901邯鄲:101091001保定:101090201廊坊:101090601鄭州:101180101新鄉:101180301許昌:101180401平頂山:101180501信陽:101180601南陽:101180701開封:101180801洛陽:101180901商丘:101181001焦作:101181101鶴壁:101181201濮陽:101181301周口:101181401漯河:101181501駐馬店:101181601三門峽:101181701濟源:101181801安陽:101180201合肥:101220101蕪湖:101220301淮南:101220401馬鞍山:101220501安慶:101220601宿州:101220701阜陽:101220801亳州:101220901黃山:101221001滁州:101221101淮北:101221201銅陵:101221301宣城:101221401六安:101221501巢湖:101221601池州:101221701蚌埠:101220201杭州:101210101舟山:101211101湖州:101210201嘉興:101210301金華:101210901紹興:101210501台州:101210601溫州:101210701麗水:101210801衢州:101211001寧波:101210401重慶:101040100合川:101040300南川:101040400江津:101040500萬盛:101040600渝北:101040700北碚:101040800巴南:101040900長壽:101041000黔江:101041100萬州天城:101041200萬州龍寶:101041300涪陵:101041400開縣:101041500城口:101041600雲陽:101041700巫溪:101041800奉節:101041900巫山:101042000潼南:101042100墊江:101042200梁平:101042300忠縣:101042400石柱:101042500大足:101042600榮昌:101042700銅梁:101042800璧山:101042900豐都:101043000武隆:101043100彭水:101043200綦江:101043300酉陽:101043400秀山:101043600沙坪壩:101043700永川:101040200福州:101230101泉州:101230501漳州:101230601龍岩:101230701晉江:101230509南平:101230901廈門:101230201寧德:101230301莆田:101230401三明:101230801蘭州:101160101平涼:101160301慶陽:101160401武威:101160501金昌:101160601嘉峪關:101161401酒泉:101160801天水:101160901武都:101161001臨夏:101161101合作:101161201白銀:101161301定西:101160201張掖:101160701廣州:101280101惠州:101280301梅州:101280401汕頭:101280501深圳:101280601珠海:101280701佛山:101280800肇慶:101280901湛江:101281001江門:101281101河源:101281201清遠:101281301雲浮:101281401潮州:101281501東莞:101281601中山:101281701陽江:101281801揭陽:101281901茂名:101282001汕尾:101282101韶關:101280201南寧:101300101柳州:101300301來賓:101300401桂林:101300501梧州:101300601防城港:101301401貴港:101300801玉林:101300901百色:101301001欽州:101301101河池:101301201北海:101301301崇左:101300201賀州:101300701貴陽:101260101安順:101260301都勻:101260401興義:101260906銅仁:101260601畢節:101260701六盤水:101260801遵義:101260201凱里:101260501昆明:101290101紅河:101290301文山:101290601玉溪:101290701楚雄:101290801普洱:101290901昭通:101291001臨滄:101291101怒江:101291201香格里拉:101291301麗江:101291401德宏:101291501景洪:101291601大理:101290201曲靖:101290401保山:101290501呼和浩特:101080101烏海:101080301集寧:101080401通遼:101080501阿拉善左旗:101081201鄂爾多斯:101080701臨河:101080801錫林浩特:101080901呼倫貝爾:101081000烏蘭浩特:101081101包頭:101080201赤峰:101080601南昌:101240101上饒:101240301撫州:101240401宜春:101240501鷹潭:101241101贛州:101240701景德鎮:101240801萍鄉:101240901新余:101241001九江:101240201吉安:101240601武漢:101200101黃岡:101200501荊州:101200801宜昌:101200901恩施:101201001十堰:101201101神農架:101201201隨州:101201301荊門:101201401天門:101201501仙桃:101201601潛江:101201701襄樊:101200201鄂州:101200301孝感:101200401黃石:101200601咸寧:101200701成都:101270101自貢:101270301綿陽:101270401南充:101270501達州:101270601遂寧:101270701廣安:101270801巴中:101270901瀘州:101271001宜賓:101271101內江:101271201資陽:101271301樂山:101271401眉山:101271501涼山:101271601雅安:101271701甘孜:101271801阿壩:101271901德陽:101272001廣元:101272101攀枝花:101270201銀川:101170101中衛:101170501固原:101170401石嘴山:101170201吳忠:101170301西寧:101150101黃南:101150301海北:101150801果洛:101150501玉樹:101150601海西:101150701海東:101150201海南:101150401濟南:101120101濰坊:101120601臨沂:101120901菏澤:101121001濱州:101121101東營:101121201威海:101121301棗庄:101121401日照:101121501萊蕪:101121601聊城:101121701青島:101120201淄博:101120301德州:101120401煙台:101120501濟寧:101120701泰安:101120801西安:101110101延安:101110300榆林:101110401銅川:101111001商洛:101110601安康:101110701漢中:101110801寶雞:101110901咸陽:101110200渭南:101110501太原:101100101臨汾:101100701運城:101100801朔州:101100901忻州:101101001長治:101100501大同:101100201陽泉:101100301晉中:101100401晉城:101100601呂梁:101101100烏魯木齊:101130101石河子:101130301昌吉:101130401吐魯番:101130501庫爾勒:101130601阿拉爾:101130701阿克蘇:101130801喀什:101130901伊寧:101131001塔城:101131101哈密:101131201和田:101131301阿勒泰:101131401阿圖什:101131501博樂:101131601克拉瑪依:101130201拉薩:101140101山南:101140301阿里:101140701昌都:101140501那曲:101140601日喀則:101140201林芝:101140401台北縣:101340101高雄:101340201台中:101340401海口:101310101三亞:101310201東方:101310202臨高:101310203澄邁:101310204儋州:101310205昌江:101310206白沙:101310207瓊中:101310208定安:101310209屯昌:101310210瓊海:101310211文昌:101310212保亭:101310214萬寧:101310215陵水:101310216西沙:101310217南沙島:101310220樂東:101310221五指山:101310222瓊山:101310102長沙:101250101株洲:101250301衡陽:101250401郴州:101250501常德:101250601益陽:101250700婁底:101250801邵陽:101250901岳陽:101251001張家界:101251101懷化:101251201黔陽:101251301永州:101251401吉首:101251501湘潭:101250201南京:101190101鎮江:101190301蘇州:101190401南通:101190501揚州:101190601宿遷:101191301徐州:101190801淮安:101190901連雲港:101191001常州:101191101泰州:101191201無錫:101190201鹽城:101190701哈爾濱:101050101牡丹江:101050301佳木斯:101050401綏化:101050501黑河:101050601雙鴨山:101051301伊春:101050801大慶:101050901七台河:101051002雞西:101051101鶴崗:101051201齊齊哈爾:101050201大興安嶺:101050701長春:101060101延吉:101060301四平:101060401白山:101060901白城:101060601遼源:101060701松原:101060801吉林:101060201通化:101060501沈陽:101070101鞍山:101070301撫順:101070401本溪:101070501丹東:101070601葫蘆島:101071401營口:101070801阜新:101070901遼陽:101071001鐵嶺:101071101朝陽:101071201盤錦:101071301大連:101070201錦州:101070701
1. XML介面 http://flash.weather.com.cn/wmaps/xml/china.xml 這個是全國天氣的根節點,列出所有的省,其中的pyName欄位是各個省XML的文件名,比如北京的是beijing,那就意味著北京的XML地址為 http://flash.weather.com.cn/wmaps/xml/beijing.xml 一個省的天氣,其中列出該省各個市的數據,北京就列出各個區。 tmp1是最低溫低,tmp2是最高溫度,url非常重要,我們一會兒再說。state1和state2是神馬轉神馬,每個數代表一個天氣現象。天氣現象非常多,我本想全部分析出來,後來直接放棄了這個想法。因為我看到了一個城市的天氣現象的編碼是26...我現在知道的有0.晴 1.多雲 2.陰 6.雨夾雪 7.小雨 8.中雨 13.陣雪 14.小雪 其中後來發現知道這個沒用,這個數字的主要作用是檢索圖片的!!!
2. 圖片介面 http://m.weather.com.cn/img/c0.gif http://m.weather.com.cn/img/b0.gif http://www.weather.com.cn/m/i/weatherpic/29x20/d0.gif http://www.weather.com.cn/m2/i/icon_weather/29x20/n00.gif 這個圖就是天氣現象0(晴)的圖片,其他天氣現象的圖片依此類推。c打頭的圖片是20*20像素的,b打頭的是50*46像素的,d打頭的是反白的圖標,29*20像素,n打頭的是夜間反白圖標,29*20像素,注意這里的文件名是兩位數字! 也許還有更多的圖標,等待大家發掘啦~
3. JSON介面 真沒想到~居然有JSON介面~JSON在iPhone上分析起來要比XML簡單很多 http://m.weather.com.cn/data/101010200.html 這個是北京的JSON數據,那個HTML的名字是根據上文XML中的url得到的。這個JSON中包含了實時數據、7天天氣預報、氣象指數等豐富的數據
獲取省級代碼:http://www.weather.com.cn/data/list3/city.xml?level=1獲取城市代碼(比如安徽是22):http://www.weather.com.cn/data/list3/city22.xml?level=2獲取區域代碼(比如安慶是2206):http://www.weather.com.cn/data/list3/city2206.xml?level=3獲取到安徽省安慶市望江縣的代碼是220607然後去加上中國代碼請求URL:http://m.weather.com.cn/data/101220607.html就可以獲取當地天氣。
另外再給幾個有用的探索得到的URL:天氣 FLASH實況:http://flash.weather.com.cn/sk2/101220607.xml實況FLASH:http://flash.weather.com.cn/sk2/shikuang.swf?id=101220607
三級選擇菜單(註明,這里有四個INPUT,其中有一個被隱藏了,可用FIREFOX改下源代碼查看):http://www.weather.com.cn/static/custom/search3.htm
實時天氣(很有用哦):http://www.weather.com.cn/data/sk/101220607.html
1. XML介面
http://flash.weather.com.cn/wmaps/xml/china.xml
這個是全國天氣的根節點,列出所有的省,其中的pyName欄位是各個省XML的文件名,比如北京的是beijing,那就意味著北京的XML地址為
http://flash.weather.com.cn/wmaps/xml/beijing.xml
一個省的天氣,其中列出該省各個市的數據,北京就列出各個區。
tmp1是最低溫低,tmp2是最高溫度,url非常重要,我們一會兒再說。state1和state2是神馬轉神馬,每個數代表一個天氣現 象。天氣現象非常多,我本想全部分析出來,後來直接放棄了這個想法。因為我看到了一個城市的天氣現象的編碼是26...我現在知道的有0.晴 1.多雲 2.陰 6.雨夾雪 7.小雨 8.中雨 13.陣雪 14.小雪
其中後來發現知道這個沒用,這個數字的主要作用是檢索圖片的!!!
2. 圖片介面
http://m.weather.com.cn/img/c0.gif
http://m.weather.com.cn/img/b0.gif
http://www.weather.com.cn/m/i/weatherpic/29x20/d0.gif
http://www.weather.com.cn/m2/i/icon_weather/29x20/n00.gif
這個圖就是天氣現象0(晴)的圖片,其他天氣現象的圖片依此類推。c打頭的圖片是20*20像素的,b打頭的是50*46像素的,d打頭的是反白的圖標,29*20像素,n打頭的是夜間反白圖標,29*20像素,注意這里的文件名是兩位數字!
3. JSON介面
http://m.weather.com.cn/data/101010100.htmlhttp://www.weather.com.cn/data/sk/101010100.htmlhttp://www.weather.com.cn/data/cityinfo/101010100.html
『叄』 請問如何實現:在網頁中選擇了國家,下面自動出現該國家的省名供選擇
<script type="text/javascript">
//定義了城市的二維數組,裡面的順序跟省份的順序是相同的。通過selectedIndex獲得省份的下標值來得到相應的城市數組
var city=[
["北京","天津","上海","重慶","香港","澳門"],
["石家莊","唐山","秦皇島","邯鄲","邢台","保定","張家口","承德","滄州","廊坊","衡水"],
["太原","大同","陽泉","長治","晉城","朔州","晉中","運城","忻州","臨汾","呂梁"],
["呼和浩特","包頭","烏海","赤峰","通遼","鄂爾多斯","呼倫貝爾","巴彥淖爾","烏蘭察布","興安","錫林郭勒","阿拉善"],
["沈陽","大連","鞍山","撫順","本溪","丹東","錦州","營口","阜新","遼陽","盤錦","鐵嶺","朝陽","葫蘆島"],
["長春","吉林","四平","遼源","通化","白山","松原","白城","延邊"],
["哈爾濱","齊齊哈爾","雞西","鶴崗","雙鴨山","大慶","伊春","佳木斯","七台河","牡丹江","黑河","綏化","大興安嶺"],
["南京","蘇州","揚州","無錫","徐州","常州","南通","連雲港","淮安","鹽城","鎮江","泰州","宿遷"],
["杭州","寧波","溫州","嘉興","湖州","紹興","金華","衢州","舟山","台州","麗水"],
["合肥","蕪湖","蚌埠","淮南","馬鞍山","淮北","銅陵","安慶","黃山","滁州","阜陽","宿州","巢湖","六安","亳州","池州","宣城"],
["福州","寧德","南平","廈門","莆田","三明","泉州","漳州"],
["南昌","上饒","萍鄉","九江","景德鎮","新余","鷹潭","贛州","吉安","宜春","撫州"],
["濟南","青島","淄博","棗庄","東營","煙台","濰坊","威海","濟寧","泰安","日照","萊蕪","臨沂","德州","聊城","濱州","菏澤"],
["鄭州","開封","洛陽","平頂山","焦作","鶴壁","新鄉","安陽","濮陽","漯河","許昌","三門峽","南陽","商丘","信陽","周口","駐馬店"],
["武漢","十堰","襄樊","鄂州","黃石","荊州","宜昌","荊門","孝感","黃岡","咸寧","隨州","恩施"],
["長沙","株洲","湘潭","岳陽","邵陽","常德","衡陽","張家界","益陽","郴州","永州","懷化","婁底","湘西"],
["廣州","清遠","潮州","東莞","珠海","深圳","汕頭","韶關","佛山","江門","湛江","茂名","肇慶","惠州","梅州","汕尾","陽江","河源","中山","揭陽","雲浮"],
["南寧","柳州","桂林","梧州","北海","防城港","欽州","貴港","玉林","百色","賀州","河池","來賓","崇左"],
["海口","三亞"],
["成都","自貢","攀枝花","瀘州","德陽","綿陽","廣元","遂寧","內江","樂山","南充","宜賓","廣安","達州","眉山","雅安","巴中","資陽","阿壩","甘孜","涼山"],
["貴陽","六盤水","遵義","安順","銅仁","畢節","黔西南","黔東南","黔南"],
["昆明","曲靖","玉溪","保山","昭通","麗江","普洱","臨滄","文山","紅河","西雙版納","楚雄","大理","德宏","怒江","迪慶"],
["拉薩","昌都","山南","日喀則","那曲","阿里","林芝"],
["西安","銅川","寶雞","咸陽","渭南","延安","漢中","榆林","安康","商洛"],
["蘭州","白銀","定西","敦煌","嘉峪關","金昌","天水","武威","張掖","平涼","酒泉","慶陽","臨夏","隴南","甘南"],
["西寧","海東","海北","黃南","海南","果洛","玉樹","海西"],
["銀川","石嘴山","吳忠","固原","中衛"],
["烏魯木齊","克拉瑪依","吐魯番","哈密","和田","阿克蘇","喀什","克孜勒蘇柯爾克孜","巴音郭楞蒙古","昌吉","博爾塔拉蒙古","伊犁哈薩克","阿勒泰"],
["台北","高雄","基隆","台中","台南","新竹","嘉義"]
];
function getCity(){
//獲得省份下拉框的對象
var sltProvince=document.forms[0].province;
//獲得城市下拉框的對象
var sltCity=document.forms[0].city;
//得到對應省份的城市數組
var provinceCity=city[sltProvince.selectedIndex - 1];
//清空城市下拉框,僅留提示選項
sltCity.length=1;
//將城市數組中的值填充到城市下拉框中
for(var i=0;i<provinceCity.length;i++){
sltCity[i+1]=new Option(provinceCity[i],provinceCity[i]);
}
}
</script>
<form action="#" method="POST" name="myform" target="_self" id="myform">
<select name="province" onChange="getCity()">
<option value="null" disabled="disabled">請選擇所在省份</option>
<option value="直轄市">直轄市</option>
<option value="河北">河北</option>
<option value="山西">山西</option>
<option value="內蒙古">內蒙古</option>
<option value="遼寧">遼寧</option>
<option value="吉林">吉林</option>
<option value="黑龍江">黑龍江</option>
<option value="江蘇">江蘇</option>
<option value="浙江">浙江</option>
<option value="安徽">安徽 </option>
<option value="福建">福建 </option>
<option value="江西">江西</option>
<option value="山東">山東</option>
<option value="河南">河南</option>
<option value="湖北">湖北</option>
<option value="湖南">湖南</option>
<option value="廣東">廣東</option>
<option value="廣西">廣西</option>
<option value="海南">海南</option>
<option value="四川">四川</option>
<option value="貴州">貴州</option>
<option value="雲南">雲南</option>
<option value="西藏">西藏</option>
<option value="陝西">陝西 </option>
<option value="甘肅">甘肅 </option>
<option value="青海">青海</option>
<option value="寧夏">寧夏</option>
<option value="新疆">新疆</option>
<option value="台灣">台灣</option>
</select>
<select name="city">
<option selected="selected" value="null">請選擇所在城市</option>
</select>
</form> 直接用就可以了。這是 省市 2級聯動
『肆』 我現在需要一個二級聯動城市的下拉菜單asp源代碼,同志們幫幫忙啊!
<SCRIPT LANGUAGE="JavaScript">
function Dsy()
{
this.Items = {};
}
Dsy.prototype.add = function(id,iArray)
{
this.Items[id] = iArray;
}
Dsy.prototype.Exists = function(id)
{
if(typeof(this.Items[id]) == "undefined") return false;
return true;
}
function change(v){
var str="0";
for(i=0;i<v;i++){ str+=("_"+(document.getElementById(s[i]).selectedIndex-1));};
var ss=document.getElementById(s[v]);
with(ss){
length = 0;
options[0]=new Option(opt0[v],opt0[v]);
if(v && document.getElementById(s[v-1]).selectedIndex>0 || !v)
{
if(dsy.Exists(str)){
ar = dsy.Items[str];
for(i=0;i<ar.length;i++)options[length]=new Option(ar[i],ar[i]);
if(v)options[1].selected = true;
}
}
if(++v<s.length){change(v);}
}
}
var dsy = new Dsy();
dsy.add("0",["北京市","天津市","河北省","山西省","內蒙古","遼寧省","吉林省","黑龍江省","上海市","江蘇省","浙江省","安徽省","福建省","江西省","山東省","河南省","湖北省","湖南省","廣東省","廣西自治區","海南省","重慶市","四川省","貴州省","雲南省","西藏自治區","陝西省","甘肅省","青海省","寧夏回族自治區","新疆維吾爾自治區","香港特別行政區","澳門特別行政區","台灣省","其它"]);
dsy.add("0_0",["北京","東城區","西城區","崇文區","宣武區","朝陽區","豐台區","石景山區"," 海淀區(中關村)","門頭溝區","房山區","通州區","順義區","昌平區","大興區","懷柔區","平谷區","密雲縣","延慶縣","其他"]);
dsy.add("0_1",["和平區","河東區","河西區","南開區","紅橋區","塘沽區","漢沽區","大港區","西青區","津南區","武清區","薊縣","寧河縣","靜海縣","其他"]);
dsy.add("0_2",["石家莊市","張家口市","承德市","秦皇島市","唐山市","廊坊市","衡水市","滄州市","邢台市","邯鄲市","保定市","其他"]);
dsy.add("0_3",["太原市","朔州市","大同市","長治市","晉城市","忻州市","晉中市","臨汾市","呂梁市","運城市","其他"]);
dsy.add("0_4",["呼和浩特市","包頭市","赤峰市","呼倫貝爾市","鄂爾多斯市","烏蘭察布市","巴彥淖爾市","興安盟","阿拉善盟","錫林郭勒盟","其他"]);
dsy.add("0_5",["沈陽市","朝陽市","阜新市","鐵嶺市","撫順市","丹東市","本溪市","遼陽市","鞍山市","大連市","營口市","盤錦市","錦州市","葫蘆島市","其他"]);
dsy.add("0_6",["長春市","白城市","吉林市","四平市","遼源市","通化市","白山市","延邊朝鮮族自治州","其他"]);
dsy.add("0_7",["哈爾濱市","七台河市","黑河市","大慶市","齊齊哈爾市","伊春市","佳木斯市","雙鴨山市","雞西市","大興安嶺地區(加格達奇)","牡丹江","鶴崗市","綏化市 ","其他"]);
dsy.add("0_8",["黃浦區","盧灣區","徐匯區","長寧區","靜安區","普陀區","閘北區","虹口區","楊浦區","閔行區","寶山區","嘉定區","浦東新區","金山區","松江區","青浦區","南匯區","奉賢區","崇明縣","其他"]);
dsy.add("0_9",["南京市","徐州市","連雲港市","宿遷市","淮安市","鹽城市","揚州市","泰州市","南通市","鎮江市","常州市","無錫市","蘇州市","其他"]);
dsy.add("0_10",["杭州市","湖州市","嘉興市","舟山市","寧波市","紹興市","衢州市","金華市","台州市","溫州市","麗水市","其他"]);
dsy.add("0_11",["合肥市","宿州市","淮北市","亳州市","阜陽市","蚌埠市","淮南市","滁州市","馬鞍山市","蕪湖市","銅陵市","安慶市","黃山市","六安市","巢湖市","池州市","宣城市","其他"]);
dsy.add("0_12",["福州市","南平市","莆田市","三明市","泉州市","廈門市","漳州市","龍岩市","寧德市","其他"]);
dsy.add("0_13",["南昌市","九江市","景德鎮市","鷹潭市","新余市","萍鄉市","贛州市","上饒市","撫州市","宜春市","吉安市","其他"]);
dsy.add("0_14",["濟南市","聊城市","德州市","東營市","淄博市","濰坊市","煙台市","威海市","青島市","日照市","臨沂市","棗庄市","濟寧市","泰安市","萊蕪市","濱州市","菏澤市","其他"]);
dsy.add("0_15",["鄭州市","三門峽市","洛陽市","焦作市","新鄉市","鶴壁市","安陽市","濮陽市","開封市","商丘市","許昌市","漯河市","平頂山市","南陽市","信陽市","周口市","駐馬店市","其他"]);
dsy.add("0_16",["武漢市","十堰市","襄樊市","荊門市","孝感市","黃岡市","鄂州市","黃石市","咸寧市","荊州市","宜昌市","隨州市","恩施土家族苗族自治州","仙桃市","天門市","潛江市","神農架林區","其他"]);
dsy.add("0_17",["長沙市","張家界市","常德市","益陽市","岳陽市","株洲市","湘潭市","衡陽市","郴州市","永州市","邵陽市","懷化市","婁底市","湘西土家族苗族自治州","其他"]);
dsy.add("0_18",["廣州市","清遠市市","韶關市","河源市","梅州市","潮州市","汕頭市","揭陽市","汕尾市","惠州市","東莞市","深圳市","珠海市","中山市","江門市","佛山市","肇慶市","雲浮市","陽江市","茂名市","湛江市","其他"]);
dsy.add("0_19",["南寧市","桂林市","柳州市","梧州市","貴港市","玉林市","欽州市","北海市","防城港市","崇左市","百色市","河池市","來賓市","賀州市","其他"]);
dsy.add("0_20",["海口市","三亞市","其他"]);
dsy.add("0_21",["渝中區","大渡口區","江北區","沙坪壩區","九龍坡區","南岸區","北碚區","萬盛區","雙橋區","渝北區","巴南區","萬州區","涪陵區","黔江區","長壽區","合川市","永川市","江津市","南川市","綦江縣","潼南縣","銅梁縣","大足縣","璧山縣","墊江縣","武隆縣","豐都縣","城口縣","開縣","巫溪縣","巫山縣","奉節縣","雲陽縣","忠縣","石柱土家族自治縣","彭水苗族土家族自治縣","酉陽土家族苗族自治縣","秀山土家族苗族自治縣","其他"]);
dsy.add("0_22",["成都市","廣元市","綿陽市","德陽市","南充市","廣安市","遂寧市","內江市","樂山市","自貢市","瀘州市","宜賓市","攀枝花市","巴中市","資陽市","眉山市","雅安","阿壩藏族羌族自治州","甘孜藏族自治州","涼山彝族自治州縣","其他"]);
dsy.add("0_23",["貴陽市","六盤水市","遵義市","安順市","畢節地區","銅仁地區","黔東南苗族侗族自治州","黔南布依族苗族自治州","黔西南布依族苗族自治州","其他"]);
dsy.add("0_24",["昆明市","曲靖市","玉溪市","保山市","昭通市","麗江市","普洱市","臨滄市","寧德市","德宏傣族景頗族自治州","怒江僳僳族自治州","楚雄彝族自治州","紅河哈尼族彝族自治州","文山壯族苗族自治州","大理白族自治州","迪慶藏族自治州","西雙版納傣族自治州","其他"]);
dsy.add("0_25",["拉薩市","那曲地區","昌都地區","林芝地區","山南地區","日喀則地區","阿里地區","其他"]);
dsy.add("0_26",["西安市","延安市","銅川市","渭南市","咸陽市","寶雞市","漢中市","安康市","商洛市","其他"]);
dsy.add("0_27",["蘭州市 ","嘉峪關市","金昌市","白銀市","天水市","武威市","酒泉市","張掖市","慶陽市","平涼市","定西市","隴南市","臨夏回族自治州","甘南藏族自治州","其他"]);
dsy.add("0_28",["西寧市","海東地區","海北藏族自治州","黃南藏族自治州","玉樹藏族自治州","海南藏族自治州","果洛藏族自治州","海西蒙古族藏族自治州","其他"]);
dsy.add("0_29",["銀川市","石嘴山市","吳忠市","固原市","中衛市","其他"]);
dsy.add("0_30",["烏魯木齊市","克拉瑪依市","喀什地區","阿克蘇地區","和田地區","吐魯番地區","哈密地區","塔城地區","阿勒泰地區","克孜勒蘇柯爾克孜自治州","博爾塔拉蒙古自治州","昌吉回族自治州 伊犁哈薩克自治州","巴音郭楞蒙古自治州","河子市","阿拉爾市","五家渠市","圖木舒克市","其他"]);
dsy.add("0_31",["香港","其他"]);
dsy.add("0_31",["澳門","其他"])
dsy.add("0_32",["台灣","其他"])
//-->
</SCRIPT>
<SCRIPT LANGUAGE = JavaScript>
var s=["s1","s2"];
var opt0 = ["請選擇","請選擇"];
function setup()
{
for(i=0;i<s.length-1;i++)
document.getElementById(s[i]).onchange=new Function("change("+(i+1)+")");
change(0);
}
</SCRIPT>
調用:<select name="lz_sf" id="s1">
<option></option></select>
<select name="lz_sx" id="s2">
<option></option></select>
<SCRIPT language="javascript">
setup()
</SCRIPT>