<!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>
<title></title>
<script type="text/javascript">
function method() {
alert("xixi");
}
function selectCitys(){
var cityArray = new Array();
//cityArray[0] = ["郑州","新乡","焦作","开封"];
//cityArray[1] = ["广州","珠海","深圳"];
//cityArray[2] = ["西安","宝鸡","渭南","汉中"];
cityArray['hn'] = ["郑州","新乡","焦作","开封"];
cityArray['gd'] = ["广州","珠海","深圳"];
cityArray['shx'] = ["西安","宝鸡","渭南","汉中"];
var s = document.getElementById("sheng").value;
if(s != "") {
//清空city中的option
document.getElementById("city").options.length = 1;
for(var i in cityArray[s]) {
var city = cityArray[s][i];
var option = new Option(city,city);
document.getElementById("city").options.add(option);
}
}
/*var s = document.getElementById("sheng");
if(s.selectedIndex != 0) {
//获取选中的省对应数组中的索引
var index = s.selectedIndex - 1;
//清空city中的option
document.getElementById("city").options.length = 1;
for(var i in cityArray[index]) {
var city = cityArray[index][i];
var option = new Option(city,city);
document.getElementById("city").options.add(option);
}
}
*/
}
</script>
</head>
<body>
<!--
<input type="text" name="" id="" οnchange="method()" />
-->
<select name="" id="sheng" οnchange="selectCitys()">
<option value="">-- 请选择省 --</option>
<option value="hn">河南</option>
<option value="gd">广东</option>
<option value="shx">陕西</option>
</select>
<select name="" id="city">
<option value="">-- 请选择城市 --</option>
</select>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function method() {
alert("xixi");
}
function selectCitys(){
var cityArray = new Array();
//cityArray[0] = ["郑州","新乡","焦作","开封"];
//cityArray[1] = ["广州","珠海","深圳"];
//cityArray[2] = ["西安","宝鸡","渭南","汉中"];
cityArray['hn'] = ["郑州","新乡","焦作","开封"];
cityArray['gd'] = ["广州","珠海","深圳"];
cityArray['shx'] = ["西安","宝鸡","渭南","汉中"];
var s = document.getElementById("sheng").value;
if(s != "") {
//清空city中的option
document.getElementById("city").options.length = 1;
for(var i in cityArray[s]) {
var city = cityArray[s][i];
var option = new Option(city,city);
document.getElementById("city").options.add(option);
}
}
/*var s = document.getElementById("sheng");
if(s.selectedIndex != 0) {
//获取选中的省对应数组中的索引
var index = s.selectedIndex - 1;
//清空city中的option
document.getElementById("city").options.length = 1;
for(var i in cityArray[index]) {
var city = cityArray[index][i];
var option = new Option(city,city);
document.getElementById("city").options.add(option);
}
}
*/
}
</script>
</head>
<body>
<!--
<input type="text" name="" id="" οnchange="method()" />
-->
<select name="" id="sheng" οnchange="selectCitys()">
<option value="">-- 请选择省 --</option>
<option value="hn">河南</option>
<option value="gd">广东</option>
<option value="shx">陕西</option>
</select>
<select name="" id="city">
<option value="">-- 请选择城市 --</option>
</select>
</body>
</html>