< html > |
< head > |
< meta http-equiv = "Content-Type" content = "text/html; charset=gb2312" /> |
< title >用数组作级联</ title > |
< script language = "javascript" > |
///用数组作级联 |
function selectProvincesArray(){ |
var cityList=new Array(); |
cityList['四川省']=['成都','绵阳','眉山','雅安','自贡']; |
cityList['云南省']=['昆明','丽江','大理']; |
cityList['浙江省']=['杭州','嘉兴','义乌']; |
///获得省份的索引 |
var pIndex=document.forms.selectProvinceArray.value; |
alert(pIndex); |
var newpotion3; |
document.forms.selectCityArray.options.length=0; |
for(var j in cityList[pIndex]){ |
newpotion3=new Option(cityList[pIndex][j],cityList[pIndex][j]); |
document.forms.selectCityArray.options.add(newpotion3); |
} |
} |
</ script > |
< style type = "text/css" > |
select { |
height: 300px; |
float: left; |
} |
</ style > |
</ head > |
< body > |
< form name = "forms" > |
< center > |
< table > |
< tr > |
< td width = "298" height = "40" colspan = "3" >< font color = "#CCCCCC" size = "+1" >---------用数组做级联效果----------</ font ></ td > |
</ tr > |
< tr > |
< td height = "100" colspan = "3" >< select name = "selectProvinceArray" size = "2" onChange = "selectProvincesArray()" > |
< option >--请选择所在省份--</ option > |
< option value = "四川省" >四川省</ option > |
< option value = "云南省" >云南省</ option > |
< option value = "浙江省" >浙江省</ option > |
</ select > |
< select name = "selectCityArray" size = "3" > |
< option >--请选择所在城市--</ option > |
</ select ></ td > |
</ tr > |
</ table > |
</ center > |
</ form > |
</ body > |
</ html > |