0
以下程序可以在Windows 7中的Chrome,Firefox,Safari上運行,但無法在IE上運行。如何改進並保持簡潔?需要javascript動態級聯選擇選項的簡明實現
<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>