十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
document.cascadeForm这种获取form的写法,只有古老的ie里面才支持,请使用标准的写法
成都创新互联公司专注于海陵网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供海陵营销型网站建设,海陵网站制作、海陵网页设计、海陵网站官网定制、重庆小程序开发服务,打造海陵网络公司原创品牌,更为您提供海陵网站排名全网营销落地服务。
document.forms['cascadeForm']
另外,select的联动事件不应该绑定在onclick上,应该绑定在onchange上吧?
这里有一个js的多级联动下拉菜单
可以自定义位置和样式 比较实用
里面有教程和源码
写的似乎有点麻烦,不如直接在下拉列表的Option里添加。
我简单给你写个。
script language="javascript"
var arr=new Array();
arr["广州01"]=["东城区","东城区","越秀区"];
arr["广州02"]=["萝岗区","天河区","南沙区"];
arr["广州03"]=["越秀区","盐田区","龙岗区"];
function Test()
{
var province=document.getElementById("province").value;
var district=document.getElementById("district");
//清空
district.length=1;
for(var i=0;iarr[province].length;i++)
{
var opt=new Option(arr[province][i],arr[province][i]);
district.options.add(opt);
}
}
/script
body
select id="province" onchange="Test()"
option--请选择--/option
option value="广州01"广州01/option
option value="广州02"广州02/option
option value="广州03"广州03/option
/select
select id="district"option--请选择--/option/select
/body
对于一个多条件的查询,我们希望在选择了一个菜单项后,另外一个下拉菜单能够根据我们所选择的第一个菜单项显示其所有子菜单项。这就是本文提到的级联菜单问题。级联菜单实现的方法有很多,本文根据笔者所做的一个小实验,简单的介绍一下如何通过XML来实现级联菜单的功能。
首先要定义一个XML文件,用以存放级联菜单的信息,我们命名为query.xml,其代码如下:
?xml version="1.0" encoding="gb2312"?
info
course
text软件工程/text
value1/value
/course
course
text数据结构/text
value2/value
/course
course
text操作系统/text
value3/value
/course
course
text计算机组成原理/text
value4/value
/course
teacher
text张老师/text
value1/value
/teacher
teacher
text李老师/text
value2/value
/teacher
teacher
text刘老师/text
value3/value
/teacher
teacher
text王老师/text
value4/value
/teacher
class
text一班/text
value1/value
/class
class
text二班/text
value2/value
/class
class
text三班/text
value3/value
/class
class
text四班/text
value4/value
/class
/info
然后再创建一个HTML文件,命名为query.html
在query.html里,首先创建一个表单
form id="queryForm"
select id="keyword" name="keyword" onChange="showDetail()"
option value="default"default/option
option value="1"课程/option
option value="2"教师/option
option value="3"班级/option
/select
select id="content" name="content" onChange="showValue()"
option value="default"default/option
/select
/form
从上面的代码可以看出,当我们选择第一级菜单时,会触发showDetail方法,这是通过JavaScript来实现的,因此我们还需要定义一个showDetail方法,其实现代码如下:
function showDetail(){
var document_xml = new ActiveXObject("Microsoft.XMLDOM");
document_xml.load("query.xml"); //加载info.xml
var RootNode = document_xml.documentElement; //获得info.xml文档的根节点
var keyword = document.getElementByIdx("keyword").value;
var details; //用以存放二级菜单内容,是一个数组对象
var content = document.getElementByIdx("content");
content.options.length = 0;//先清空
if(keyword=="default"){
var option = new Option("default","default");
content.add(option);
}else{
if(keyword=="1"){
details = document_xml.getElementsByTagName_r("course");
}else if(keyword=="2"){
details = document_xml.getElementsByTagName_r("teacher");
}else if(keyword=="3"){
details = document_xml.getElementsByTagName_r("class");
}
for(var i=0;idetails.length;i++){
var xText = details[i].childNodes[0].firstChild.nodeValue; //获取文本
var xValue = details[i].childNodes[1].firstChild.nodeValue; //获取文本以应的值
var option = new Option(xText,xValue);
content.add(option);
}
}
}
从上面的代码可以看出,showDetail方法会根据一级菜单选项的不同显示对应的子菜单。这里涉及到通过JavaScript来读取xml文件的操作,可以参见源码的注释部分,记得结合xml文件里的内容一起看哦。
二级菜单显示出来之后,我们就可以进行选择了,选择之后,会调用showValue方法,把选到的子菜单项的value和text显示出来。showValue的定义如下:
function showValue(){
var content= document.getElementByIdx("content");
var contentText = content.options[content.selectedIndex].text; //获取text值
var contentValue = document.getElementByIdx("content").value; //获取文本
alert(contentValue+" "+contentText);
}
在这个方法里,要注意option当中text值的获取,它与select表单域的value的获取方式不大一样,详见代码及其注释。
把两个方法封装在head/head之间,记得要写上script language="javascript"和/script了,然后你直接打开query.xml就可以看到效果了。
不知是否对楼主有用,希望对楼主有所帮助。
给你一个三级联动,09年最新版的
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head
meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
title无标题文档/title
/head
body
select id="province" onchange="setCity(this.value);getArea()" name="province"
option value="" selected="selected"请选择/option
/select
select id="city" onchange="setCounty(this.value);getArea()" name="city" style="display:;"
option value="" selected="selected"请选择/option
/select
select id="county" name="county" onchange="getArea()" style="display:;"
option value="" selected="selected"请选择/option
/select
input type="text" name="area" id="area" value="222426" onchange="setArea();"/
input type="button" value="转" onclick="setArea();" /
script type="text/javascript"
var areaData = "110000|北京市,110100|市辖区,110101|东城区,110102|西城区,110103|崇文区,110104|宣武区,110105|朝阳区,110106|丰台区,110107|石景山区,110108|海淀区,110109|门头沟区,110111|房山区,110112|通州区,110113|顺义区,110114|昌平区,110115|大兴区,110116|怀柔区,110117|平谷区,110200|县,110228|密云县,110229|延庆县,120000|天津市,120100|市辖区,120101|和平区,120102|河东区,120103|河西区,120104|南开区,120105|河北区,120106|红桥区,120107|塘沽区,120108|汉沽区,120109|大港区,120110|东丽区,120111|西青区,120112|津南区,120113|北辰区,120114|武清区,120115|宝坻区,120200|县,120221|宁河县,120223|静海县,120225|蓟县,130000|河北省,130100|石家庄市,130101|市辖区,130102|长安区,130103|桥东区,130104|桥西区,130105|新华区,130107|井陉矿区,130108|裕华区,130121|井陉县,130123|正定县,130124|栾城县,130125|行唐县,130126|灵寿县,130127|高邑县,130128|深泽县,130129|赞皇县,130130|无极县,130131|平山县,130132|元氏县,130133|赵县,130181|辛集市,130182|藁城市,130183|晋州市,130184|新乐市,130185|鹿泉市,130200|唐山市,130201|市辖区,130202|路南区,130203|路北区,130204|古冶区,130205|开平区,130207|丰南区,130208|丰润区,130223|滦县,130224|滦南县,130225|乐亭县,130227|迁西县,130229|玉田县,130230|唐海县,130281|遵化市,130283|迁安市,130300|秦皇岛市,130301|市辖区,130302|海港区,130303|山海关区,130304|北戴河区,130321|青龙满族自治县,130322|昌黎县,130323|抚宁县,130324|卢龙县,130400|邯郸市,130401|市辖区,130402|邯山区,130403|丛台区,130404|复兴区,130406|峰峰矿区,130421|邯郸县,130423|临漳县,130424|成安县,130425|大名县,130426|涉县,130427|磁县,130428|肥乡县,130429|永年县,130430|邱县,130431|鸡泽县,130432|广平县,130433|馆陶县,130434|魏县,130435|曲周县,130481|武安市,130500|邢台市,130501|市辖区,130502|桥东区,130503|桥西区,130521|邢台县,130522|临城县,130523|内丘县,130524|柏乡县,130525|隆尧县,130526|任县,130527|南和县,130528|宁晋县,130529|巨鹿县,130530|新河县,130531|广宗县,130532|平乡县,130533|威县,130534|清河县,130535|临西县,130581|南宫市,130582|沙河市,130600|保定市,130601|市辖区,130602|新市区,130603|北市区,130604|南市区,130621|满城县,130622|清苑县,130623|涞水县,130624|阜平县,130625|徐水县,130626|定兴县,130627|唐县,130628|高阳县,130629|容城县,130630|涞源县,130631|望都县,130632|安新县,130633|易县,130634|曲阳县,130635|蠡县,130636|顺平县,130637|博野县,130638|雄县,130681|涿州市,130682|定州市,130683|安国市,130684|高碑店市,130700|张家口市,130701|市辖区,130702|桥东区,130703|桥西区,130705|宣化区,130706|下花园区,130721|宣化县,130722|张北县,130723|康保县,130724|沽源县,130725|尚义县,130726|蔚县,130727|阳原县,130728|怀安县,130729|万全县,130730|怀来县,130731|涿鹿县,130732|赤城县,130733|崇礼县,130800|承德市,130801|市辖区,130802|双桥区,130803|双滦区,130804|鹰手营子矿区,130821|承德县,130822|兴隆县,130823|平泉县,130824|滦平县,130825|隆化县,130826|丰宁满族自治县,130827|宽城满族自治县,130828|围场满族蒙古族自治县,130900|沧州市,130901|市辖区,130902|新华区,130903|运河区,130921|沧县,130922|青县,130923|东光县,130924|海兴县,130925|盐山县,130926|肃宁县,130927|南皮县,130928|吴桥县,130929|献县,130930|孟村回族自治县,130981|泊头市,130982|任丘市,130983|黄骅市,130984|河间市,131000|廊坊市,131001|市辖区,131002|安次区,131003|广阳区,131022|固安县,131023|永清县,131024|香河县,131025|大城县,131026|文安县,131028|大厂回族自治县,131081|霸州市,131082|三河市,131100|衡水市,131101|市辖区,131102|桃城区,131121|枣强县,131122|武邑县,131123|武强县,131124|饶阳县,131125|安平县,131126|故城县,131127|景县,131128|阜城县,131181|冀州市,131182|深州市,140000|山西省,140100|太原市,140101|市辖区,140105|小店区,140106|迎泽区,140107|杏花岭区,140108|尖草坪区,140109|万柏林区,140110|晋源区,140121|清徐县,140122|阳曲县,140123|娄烦县,140181|古交市,140200|大同市,140201|市辖区,140202|城区,140203|矿区,140211|南郊区,140212|新荣区,140221|阳高县,140222|天镇县,140223|广灵县,140224|灵丘县,140225|浑源县,140226|左云县,140227|大同县,140300|阳泉市,140301|市辖区,140302|城区,140303|矿区,140311|郊区,140321|平定县,140322|盂县,140400|长治市,140401|市辖区,140402|城区,140411|郊区,140421|长治县,140423|襄垣县,140424|屯留县,140425|平顺县,140426|黎城县,140427|壶关县,140428|长子县,140429|武乡县,140430|沁县,140431|沁源县,140481|潞城市,140500|晋城市,140501|市辖区,140502|城区,140521|沁水县,140522|阳城县,140524|陵川县,140525|泽州县,140581|高平市,140600|朔州市,140601|市辖区,140602|朔城区,140603|平鲁区,140621|山阴县,140622|应县,140623|右玉县,140624|怀仁县,140700|晋中市,140701|市辖区,140702|榆次区,140721|榆社县,140722|左权县,140723|和顺县,140724|昔阳县,140725|寿阳县,140726|太谷县,140727|祁县,140728|平遥县,140729|灵石县,140781|介休市,140800|运城市,140801|市辖区,140802|盐湖区,140821|临猗县,140822|万荣县,140823|闻喜县,140824|稷山县,140825|新绛县,140826|绛县,140827|垣曲县,140828|夏县,140829|平陆县,140830|芮城县,140881|永济市,140882|河津市,140900|忻州市,140901|市辖区,140902|忻府区,140921|定襄县,140922|五台县,140923|代县,140924|繁峙县,140925|宁武县,140926|静乐县,140927|神池县,140928|五寨县,140929|岢岚县,140930|河曲县,140931|保德县,140932|偏关县,140981|原平市,141000|临汾市,141001|市辖区,141002|尧都区,141021|曲沃县,141022|翼城县,141023|襄汾县,141024|洪洞县,141025|古县,141026|安泽县,141027|浮山县,141028|吉县,141029|乡宁县,141030|大宁县,141031|隰县,141032|永和县,141033|蒲县,141034|汾西县,141081|侯马市,141082|霍州市,141100|吕梁市,141101|市辖区,141102|离石区,141121|文水县,141122|交城县,141123|兴县,141124|临县,141125|柳林县,141126|石楼县,141127|岚县,141128|方山县,141129|中阳县,141130|交口县,141181|孝义市,141182|汾阳市,150000|内蒙古自治区,150100|呼和浩特市,150101|市辖区,150102|新城区,150103|回民区,150104|玉泉区,150105|赛罕区,150121|土默特左旗,150122|托克托县,150123|和林格尔县,150124|清水河县,150125|武川县,150200|包头市,150201|市辖区,150202|东河区,150203|昆都仑区,150204|青山区,150205|石拐区,150206|白云矿区,150207|九原区,150221|土默特右旗,150222|固阳县,150223|达尔罕茂明安联合旗,150300|乌海市,150301|市辖区,150302|海勃湾区,150303|海南区,150304|乌达区,150400|赤峰市,150401|市辖区,150402|红山区,150403|元宝山区,150404|松山区,150421|阿鲁科尔沁旗,150422|巴林左旗,150423|巴林右旗,150424|林西县,150425|克什克腾旗,150426|翁牛特旗,150428|喀喇沁旗,150429|宁城县,150430|敖汉旗,150500|通辽市,150501|市辖区,150502|科尔沁区,150521|科尔沁左翼中旗,150522|科尔沁左翼后旗,150523|开鲁县,150524|库伦旗,150525|奈曼旗,150526|扎鲁特旗,150581|霍林郭勒市,150600|鄂尔多斯市,150601|市辖区,150602|东胜区,150621|达拉特旗,150622|准格尔旗,150623|鄂托克前旗,150624|鄂托克旗,150625|杭锦旗,150626|乌审旗,150627|伊金霍洛旗,150700|呼伦贝尔市,150701|市辖区,150702|海拉尔区,150721|阿荣旗,150722|莫力达瓦达斡尔族自治旗,150723|鄂伦春自治旗,150724|鄂温克族自治旗,150725|陈巴尔虎旗,150726|新巴尔虎左旗,150727|新巴尔虎右旗,150781|满洲里市,150782|牙克石市,150783|扎兰屯市,150784|额尔古纳市,150785|根河市,150800|巴彦淖尔市,150801|市辖区,150802|临河区,150821|五原县,150822|磴口县,150823|乌拉特前旗,150824|乌拉特中旗,150825|乌拉特后旗,150826|杭锦后旗,150900|乌兰察布市,150901|市辖区,150902|集宁区,150921|卓资县,150922|化德县,150923|商都县,150924|兴和县,150925|凉城县,150926|察哈尔右翼前旗,150927|察哈尔右翼中旗,150928|察哈尔右翼后旗,150929|四子王旗,150981|丰镇市,152200|兴安盟,152201|乌兰浩特市,152202|阿尔山市,152221|科尔沁右翼前旗,152222|科尔沁右翼中旗,152223|扎赉特旗,152224|突泉县,152500|锡林郭勒盟,152501|二连浩特市,152502|锡林浩特市,152522|阿巴嘎旗,152523|苏尼特左旗,152524|苏尼特右旗,152525|东乌珠穆沁旗,152526|西乌珠穆沁旗,152527|太仆寺旗,152528|镶黄旗,152529|正镶白旗,152530|正蓝旗,152531|多伦县,152900|阿拉善盟,152921|阿拉善左旗,152922|阿拉善右旗,152923|额济纳旗,210000|辽宁省,210100|沈阳市,210101|市辖区,210102|和平区,210103|沈河区,210104|大东区,210105|皇姑区,210106|铁西区,210111|苏家屯区,210112|东陵区,210113|沈北新区,210114|于洪区,210122|辽中县,210123|康平县,210124|法库县,210181|新民市,210200|大连市,210201|市辖区,210202|中山区,210203|西岗区,210204|沙河口区,210211|甘井子区,210212|旅顺口区,210213|金州区,210224|长海县,210281|瓦房店市,210282|普兰店市,210283|庄河市,210300|鞍山市,210301|市辖区,210302|铁东区,210303|铁西区,210304|立山区,210311|千山区,210321|台安县,210323|岫岩满族自治县,210381|海城市,210400|抚顺市,210401|市辖区,210402|新抚区,210403|东洲区,210404|望花区,210411|顺城区,210421|抚顺县,210422|新宾满族自治县,210423|清原满族自治县,210500|本溪市,210501|市辖区,210502|平山区,210503|溪湖区,210504|明山区,210505|南芬区,210521|本溪满族自治县,210522|桓仁满族自治县,210600|丹东市,210601|市辖区,210602|元宝区,210603|振兴区,210604|振安区,210624|宽甸满族自治县,210681|东港市,210682|凤城市,210700|锦州市,210701|市辖区,210702|古塔区,210703|凌河区,210711|太和区,210726|黑山县,210727|义县,210781|凌海市,210782|北镇市,210800|营口市,210801|市辖区,210802|站前区,210803|西市区,210804|鲅鱼圈区,210811|老边区,210881|盖州市,210882|大石桥市,210900|阜新市,210901|市辖区,210902|海州区,210903|新邱区,210904|太平区,210905|清河门区,210911|细河区,210921|阜新蒙古族自治县,210922|彰武县,211000|辽阳市,211001|市辖区,211002|白塔区,211003|文圣区,211004|宏伟区,211005|弓长岭区,211011|太子河区,211021|辽阳县,211081|灯塔市,211100|盘锦市,211101|市辖区,211102|双台子区,211103|兴隆台区,211121|大洼县,211122|盘山县,211200|铁岭市,211201|市辖区,211202|银州区,211204|清河区,211221|铁岭县,211223|西丰县,211224|昌图县,211281|调兵山市,211282|开原市,211300|朝阳市,211301|市辖区,211302|双塔区,211303|龙城区,211321|朝阳县,211322|建平县,211324|喀喇沁左翼蒙古族自治县,211381|北票市,211382|凌源市,211400|葫芦岛市,211401|市辖区,211402|连山区,211403|龙港区,211404|南票区,211421|绥中县,211422|建昌县,211481|兴城市,220000|吉林省,220100|长春市,220101|市辖区,220102|南关区,220103|宽城区,220104|朝阳区,220105|二道区,220106|绿园区,220112|双阳区,220122|农安县,220181|九台市,220182|榆树市,220183|德惠市,220200|吉林市,220201|市辖区,220202|昌邑区,220203|龙潭区,220204|船营区,220211|丰满区,220221|永吉县,220281|蛟河市,220282|桦甸市,220283|舒兰市,220284|磐石市,220300|四平市,220301|市辖区,220302|铁西区,220303|铁东区,220322|梨树县,220323|伊通满族自治县,220381|公主岭市,220382|双辽市,220400|辽源市,220401|市辖区,220402|龙山区,220403|西安区,220421|东丰县,220422|东辽县,220500|通化市,220501|市辖区,220502|东昌区,220503|二道江区,220521|通化县,220523|辉南县,220524|柳河县,220581|梅河口市,220582|集安市,220600|白山市,220601|市辖区,220602|八道江区,220605|江源区,220621|抚松县,220622|靖宇县,220623|长白朝鲜族自治县,220681|临江市,220700|松原市,220701|市辖区,220702|宁江区,220721|前郭尔罗斯蒙古族自治县,220722|长岭县,220723|乾安县,220724|扶余县,220800|白城市,220801|市辖区,220802|洮北区,220821|镇赉县,220822|通榆县,220881|洮南市,220882|大安市,222400|延边朝鲜族自治州,222401|延吉市,222402|图们市,222403|敦化市,222404|珲春市,222405|龙井市,222406|和龙市,222424|汪清县,222426|安图县,230000|黑龙江省,230100|哈尔滨市,230101|市辖区,230102|道里区,230103|南岗区,230104|道外区,230108|平房区,230109|松北区,230110|香坊区,230111|呼兰区,230112|阿城区,230123|依兰县,230124|方正县,230125|宾县,230126|巴彦县,230127|木兰县,230128|通河县,230129|延寿县,230182|双城市,230183|尚志市,230184|五常市,230200|齐齐哈尔市,230201|市辖区,230202|龙沙区,230203|建华区,230204|铁锋区,230205|昂昂溪区,230206|富拉尔基区,230207|碾子山区,230208|梅里斯达斡尔族区,230221|龙江县,230223|依安县,230224|泰来县,230225|甘南县,230227|富裕县,230229|克山县,230230|克东县,230231|拜泉县,230281|讷河市,230300|鸡西市,230301|市辖区,230302|鸡冠区,230303|恒山区,230304|滴道区,230305|梨树区,230306|城子河区,230307|麻山区,230321|鸡东县,230381|虎林市,230382|密山市,230400|鹤岗市,230401|市辖区,230402|向阳区,230403|工农区,230404|南山区,230405|兴安区,230406|东山区,230407|兴山区,230421|萝北县,230422|绥滨县,230500|双鸭山市,230501|市辖区,230502|尖山区,230503|岭东区,230505|四方台区,230506|宝山区,230521|集贤县,230522|友谊县,230523|宝清县,230524|饶河县,230600|大庆市,230601|市辖区,230602|萨尔图区,230603|龙凤区,230604|让胡路区,230605|红岗区,230606|大同区,230621|肇州县,230622|肇源县,230623|林甸县,230624|杜尔伯特蒙古族自治县,230700|伊春市,230701|市辖区,230702|伊春区,230703|南岔区,230704|友好区,230705|西林区,230706|翠峦区,230707|新青区,230708|美溪区,230709|金山屯区,230710|五营区,230711|乌马河区,230712|汤旺河区,230713|带岭区,230714|乌伊岭区,230715|红星区,230716|上甘岭区,230722|嘉荫县,230781|铁力市,230800|佳木斯市,230801|市辖区,230803|向阳区,230804|前进区,230805|东风区,230811|郊区,230822|桦南县,230826|桦川县,230828|汤原县,230833|抚远县,230881|同江市,230882|富锦市,230900|七台河市,230901|市辖区,230902|新兴区,230903|桃山区,230904|茄子河区,230921|勃利县,231000|牡丹江市,231001|市辖区,231002|东安区,231003|阳明区,231004|爱民区,231005|西安区,231024|东宁县,231025|林口县,231081|绥芬河市,231083|海林市,231084|宁安市,231085|穆棱市,231100|黑河市,231101|市辖区,231102|爱辉区,231121|嫩江县,231123|逊克县,231124|孙吴县,231181|北安市,231182|五大连池市,231200|绥化市,231201|市辖区,231202|北林区,231221|望奎县,231222|兰西县,231223|青冈县,231224|庆安县,231225|明水县,231226|绥棱县,231281|安达市,231282|肇东市,231283|海伦市,232700|大兴安岭地区,232721|呼玛县,232722|塔河县,232723|漠河县,310000|上海市,310100|市辖区,310101|黄浦区,310103|卢湾区,310104|徐汇区,310105|长宁区,310106|静安区,310107|普陀区,310108|闸北区,310109|虹口区,310110|杨浦区,310112|闵行区,310113|宝山区,310114|嘉定区,310115|浦东新区,310116|金山区,310117|松江区,310118|青浦区,310119|南汇区,310120|奉贤区,310200|县,310230|崇明县,320000|江苏省,320100|南京市,320101|市辖区,320102|玄武区,320103|白下区,320104|秦淮区,320105|建邺区,320106|鼓楼区,320107|下关区,320111|浦口区,320113|栖霞区,320114|雨花台区,320115|江宁区,320116|六合区,320124|溧水县,320125|高淳县,320200|无锡市,320201|市辖区,320202|崇安区,320203|南长区,320204|北塘区,320205|锡山区,320206|惠山区,320211|滨湖区,320281|江阴市,320282|宜兴市,320300|徐州市,320301|市辖区,320302|鼓楼区,320303|云龙区,320304|九里区,320305|贾汪区,320311|泉山区,320321|丰县,320322|沛县,320323|铜山县,320324|睢宁县,320381|新沂市,320382|邳州市,320400|常州市,320401|市辖区,320402|天宁区,320404|钟楼区,320405|戚墅堰区,320411|新北区,320412|武进区,320481|溧阳市,320482|金坛市,320500|苏州市,320501|市辖区,320502|沧浪区,320503|平江区,320504|金阊区,320505|虎丘区,320506|吴中区,320507|相城区,320581|常熟市,320582|张家港市,320583|昆山市,320584|吴江市,320585|太仓市,320600|南通市,320601|市辖区,320602|崇川区,320611|港闸区,320621|海安县,320623|如东县,320681|启东市,320682|如皋市,320683|通州市,320684|海门市,320700|连云港市,320701|市辖区,320703|连云区,320705|新浦区,320706|海州区,320721|赣榆县,320722|东海县,320723|灌云县,320724|灌南县,320800|淮安市,320801|市辖区,320802|清河区,320803|楚州区,320804|淮阴区,320811|清浦区,320826|涟水县,320829|洪泽县,320830|盱眙县,320831|金湖县,320900|盐城市,320901|市辖区,320902|亭湖区,320903|盐都区,320921|响水县,320922|滨海县,320923|阜宁县,320924|射阳县,320925|建湖县,320981|东台市,320982|大丰市,321000|扬州市,321001|市辖区,321002|广陵区,321003|邗江区,321011|维扬区,321023|宝应县,321081|仪征市,321084|高邮市,321088|江都市,321100|镇江市,321101|市辖区,321102|京口区,321111|润州区,321112|丹徒区,321181|丹阳市,321182|扬中市,321183|句容市,321200|泰州市,321201|市辖区,321202|海陵区,321203|高港区,321281|兴化市,321282|靖江市,321283|泰兴市,321284|姜堰市,321300|宿迁市,321301|市辖区,321302|宿城区,321311|宿豫区,321322|沭阳县,321323|泗阳县,321324|泗洪县,330000|浙江省,330100|杭州市,330101|市辖区,330102|上城区,330103|下城区,330104|江干区,330105|拱墅区,330106|西湖区,330108|滨江区,330109|萧山区,330110|余杭区,330122|桐庐县,330127|淳安县,330182|建德市,330183|富阳市,330185|临安市,330200|宁波市,330201|市辖区,330203|海曙区,330204|江东区,330205|江北区,330206|北仑区,330211|镇海区,330212|鄞州区,330225|象山县,330226|宁海县,330281|余姚市,330282|慈溪市,330283|奉化市,330300|温州市,330301|市辖区,330302|鹿城区,330303|龙湾区,330304|瓯海区,330322|洞头县,330324|永嘉县,330326|平阳县,330327|苍南县,330328|文成县,330329|泰顺县,330381|瑞安市,330382|乐清市,330400|嘉兴市,330401|市辖区,330402|南湖区,330411|秀洲区,330421|嘉善县,330424|海盐县,330481|海宁市,330482|平湖市,330483|桐乡市,330500|湖州市,330501|市辖区,330502|吴兴区,330503|南浔区,330521|德清县,330522|长兴县,330523|安吉县,330600|绍兴市,330601|市辖区,330602|越城区,330621|绍兴县,330624|新昌县,330681|诸暨市,330682|上虞市,330683|嵊州市,330700|金华市,330701|市辖区,330702|婺城区,330703|金东区,330723|武义县,330726|浦江县,330727|磐安县,330781|兰溪市,330782|义乌市,330783|东阳市,330784|永康市,330800|衢州市,330801|市辖区,330802|柯城区,330803|衢江区,330822|常山县,330824|开化县,330825|龙游县,330881|江山市,330900|舟山市,330901|市辖区,330902|定海区,330903|普陀区,330921|岱山县,330922|嵊泗县,331000|台州市,331001|市辖区,331002|椒江区,331003|黄岩区,331004|路桥区,331021|玉环县,331022|三门县,331023|天台县,331024|仙居县,331081|温岭市,331082|临海市,331100|丽水市,331101|市辖区,331102|莲都区,331121|青田县,331122|缙云县,331123|遂昌县,331124|松阳县,331125|云和县,331126|庆元县,331127|景宁畲族自治县,331181|龙泉市,340000|安徽省,340100|合肥市,340101|市辖区,340102|瑶海区,340103|庐阳区,340104|蜀山区,340111|包河区,340121|长丰县,340122|肥东县,340123|肥西县,340200|芜湖市,340201|市辖区,340202|镜湖区,340203|弋江区,340207|鸠江区,340208|三山区,340221|芜湖县,340222|繁昌县,340223|南陵县,340300|蚌埠市,340301|市辖区,340302|龙子湖区,340303|蚌山区,340304|禹会区,340311|淮上区,340321|怀远县,340322|五河县,340323|固镇县,340400|淮南市,340401|市辖区,340402|大通区,340403|田家庵区,340404|谢家集区,340405|八公山区,340406|潘集区,340421|凤台县,340500|马鞍山市,340501|市辖区,340502|金家庄区,340503|花山区,340504|雨山区,340521|当涂县,340600|淮北市,340601|市辖区,340602|杜集区,340603|相山区,340604|烈山区,340621|濉溪县,340700|铜陵市,340701|市辖区,340702|铜官山区,340703|狮子山区,340711|郊区,340721|铜陵县,340800|安庆市,340801|市辖区,340802|迎江区,340803|大观区,340811|宜秀区,340822|怀宁县,340823|枞阳县,340824|潜山县,340825|太湖县,340826|宿松县,340827|望江县,340828|岳西县,340881|桐城市,341000|黄山市,341001|市辖区,341002|屯溪区,341003|黄山区,341004|徽州区,341021|歙县,341022|休宁县,341023|黟县,341024|祁门县,341100|滁州市,341101|市辖区,341102|琅琊区,341103|南谯区,341122|来安县,341124|全椒县,341125|定远县,341126|凤阳县,341181|天长市,341182|明光市,341200|阜阳市,341201|市辖区,341202|颍州区,341203|颍东区,341204|颍泉区,341221|临泉县,341222|太和县,341225|阜南县,341226|颍上县,341282|界首市,341300|宿州市,341301|市辖区,341302|埇桥区,341321|砀山县,341322|萧县,341323|灵璧县,341324|泗县,341400|巢湖
js代码
//级联菜单
var province = ['江西省','江苏省','浙江省','甘肃省','江西省','江苏省','浙江省','甘肃省'];
var city = Array(
new Array ('南昌市','赣州市','抚州市','上饶市'),
new Array('杭州市','温州市','宁波市'),
new Array('南京市','苏州市','昆山市','太仓市'),
new Array('兰州市','敦煌市','兰楼市'),
new Array ('南昌市','赣州市','抚州市','上饶市'),
new Array('杭州市','温州市','宁波市'),
new Array('南京市','苏州市','昆山市','太仓市'),
new Array('兰州市','敦煌市','兰楼市')
)
//遍历省份
for(var i=0;iprovince.length;i++){
var opt = document.createElement('option'); //创建一个结点
opt.value = province[i]; //在value显示
opt.innerHTML = opt.value; //页面显示
document.getElementById('big').appendChild(opt);
}
//省份值改变的时候调用函数
function show_small(){
//alert( document.getElementById('big').selectedIndex);//拿到下标
document.getElementById('small').innerHTML="";//清空 appendChild会追加
var index = document.getElementById('big').selectedIndex;
for(var i=0;icity[index-1].length;i++){ //注意下标
var opt = document.createElement('option');
opt.value = city[index-1][i];
opt.innerHTML = opt.value;
document.getElementById('small').appendChild(opt);
}
}
html代码
!-- 级联菜单--
select id="big" onchange="show_small()"
option value=""--select--/option
/select
select id="small"
option value=""--select--/option
/select
手上刚好有个二级联动的,三级联动的你可以自己看着加进去,希望对你有帮助