81,092
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script>
var selCountryOp = new Array("中国","美国","埃及");
var selCityOp = new Array("北京,上海,深圳","洛杉矶,休斯顿,华盛顿","埃及");
function creatOption(ary1,ary2,option){
for(var i=0;i<ary1.length;i++){
option[option.length] = new Option(ary1[i],ary2[i]);
}
}
function changeSel(){
selCity.options.length=0;
creatOption(selCountry.value.split(","),selCountry.value.split(","),selCity.options);
}
window.onload = function(){
creatOption(selCountryOp,selCityOp,selCountry.options);
creatOption(selCountry.value.split(","),selCountry.value.split(","),selCity.options);
}
</script>
</head>
<body>
国家:<select id="selCountry" onchange="changeSel()"></select>
<br />
城市:<select id="selCity"></select>
</body>
</html>