以下程序可以在 Windows 7 的 Chrome、Firefox、Safari 上运行,但不能在 IE 上运行。如何改进它并保持简洁?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>选择地区</title>
</head>
<body>
<form id="area">
<select id="selectProvince" onchange="setCities()"></select>
<select id="selectCity"></select>
</form>
</body>
<script>
var province_cities_map = {
北京: ['东城','西城'],
上海: ['黄浦','卢湾'],
};
function setProvinces() {
provinces = Object.keys(province_cities_map);
selectProvince.length = 0;
for (i = 0; i < provinces.length; i++) selectProvince.options[i] = new Option(provinces[i]);
setCities();
}
function setCities() {
cities = province_cities_map[selectProvince.value];
selectCity.length = 0;
for (j = 0; j < cities.length; j++) selectCity.options[j] = new Option(cities[j]);
}
setProvinces();
</script>
</html>