<html>
<head>
<style type="text/css">
</style>
</head>
<body>
<select id = "countryid" onchange="add1(this.value);">
<option value="0">--请选择--</option>
<option value="中国">中国</option>
<option value="美国">美国</option>
<option value="德国">德国</option>
<option value="日本">日本</option>
</select>
<select id="cityid">
</select>
</body>
<script type = "text/javascript">
var arr = new Array(4);
arr[0]=["中国","南京","石家庄","乌鲁木齐","北京"];
arr[1]=["美国","华盛顿","旧金山","夏威夷","休斯顿","洛杉矶"];
arr[2]=["德国","慕尼黑","柏林"];
arr[3]=["日本","北海道","东京","广岛","长崎"];
function add1(val)
{
var city1 = document.getElementById("cityid");
var options1=city1.getElementsByTagName("option");
for(var m =0;m<options1.length;m++)
{
var op =options1[m];
city1.removeChild(op);
m--;
}
for(var i = 0;i<arr.length;i++)
{
var arr1 = arr[i];
var firstvalue = arr1[0];
if(firstvalue == val)
{
for(var j =1;j<arr1.length;j++)
{
var value1 = arr1[j];
//alert(value1);
//创建option
var option1 = document.createElement("option");
//创建文本
var text1 = document.createTextNode(value1);
//把文本添加到option1里面
option1.appendChild(text1);
//添加到city1里面
city1.appendChild(option1);
}
}
}
}
</script>
</html>