关于onchange的问题,百度无结果
参照李绪成视频做的一个onchange,觉得思路上没错。。但是就是调用不到changeCity(),运行后,选择了省份,城市也没变!!求解惑
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<script LANGUAGE="JavaScript">
function changeCity(){
alter("123");
var province=["重庆","成都","上海"];
var citys=[["九龙坡区","江北区","南平"],["锦江区","成华区","青羊区"],["杨浦区","虹口区","浦东新区"]];
selected=document.getElementById("province").value;
city.length=citys[selected-1].length;
for(int i=0;i<citys[selected-1].length;i++){
city.options[i].value=i+1;
city.options[i].text=citys[selected-1][i];
}
}
</script>
<head>
<title>select</title>
</head>
<body>
<select name="province" id="province" onChange="changeCity()">
<option value="1">
重庆
</option>
<option value="2">
成都
</option>
<option value="3">
上海
</option>
</select>
<select name="city" id="city" >
<option value="1">
九龙坡区
</option>
<option value="2">
江北区
</option>
<option value="3">
南平
</option>
</select>
</body>
</html>
------解决方案--------------------<script language="JavaScript">
function changeCity(){
var province=["重庆","成都","上海"];
var citys=[["九龙坡区","江北区","南平"],["锦江区","成华区","青羊区"],["杨浦区","虹口区","浦东新区"]];
selected=document.getElementById("province").value;
city.length=citys[selected-1].length;
for(var i=0;i<citys[selected-1].length;i++){
city.options[i].value=i+1;
city.options[i].text=citys[selected-1][i];
}
}
</script>
------解决方案--------------------<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<script type="text/javascript">
function changeCity(){
alert("123"); //alert
var province=["重庆","成都","上海"];//符号错误
var citys=[["九龙坡区","江北区","南平"],["锦江区","成华区","青羊区"],["杨浦区","虹口区","浦东新区"]];
selected=document.getElementById("province").value;
city.length=citys[selected-1].length;
for(var i=0;i<citys[selected-1].length;i++){//js用var 不用int 是弱类型语言
city.options[i].value=i+1;
city.options[i].text=citys[selected-1][i];
}
}
</script>
<head>
<title>select</title>
</head>
<body>
<select name="province" id="province" onChange="changeCity()">
<option value="1">
重庆
</option>
<option value="2">
成都
</option>
<option value="3">
上海
</option>
</select>
<select name="city" id="city"