求助,外部js无法被html调用,找了好久都没找到原因
这个是html 只要是用JS实现省市下拉菜单级联。但是没有效果。如果直接将<script>写在html里是可以出效果的<html>
<head>
<script charset="utf-8" type="text/javascript" src="select.js"></script>
</head>
<body>
<form name="Form1">
<select name="province" style="WIDTH: 65px" size="1" onChange="updateCities()">
<option selected value="">-省份-</option>
<option value="安徽">安徽</option>
</select>省
<select name="cities" style="WIDTH: 65px" size="1"></select>市
<input name="GO" type="button" value="GO"></input>
</form>
</body>
</html>
这个是js代码
var default1=new Array("","");
var anhui=new Array();
anhui[0]=new Array("合肥","合肥");
anhui[1]=new Array("黄山","黄山");
anhui[2]=new Array("安庆","安庆");
anhui[3]=new Array("滁州","滁州");
anhui[4]=new Array("巢湖","巢湖");
anhui[5]=new Array("阜阳","阜阳");
anhui[6]=new Array("九华山","九华山");
var beijing=new Array();
beijing[0]=new Array("崇文","崇文");
beijing[1]=new Array("宣武","宣武");
beijing[2]=new Array("朝阳","朝阳");
beijing[3]=new Array("海淀","海淀");
function showCities(cityArray)
{
if(document.Form1.cities.options.length>cityArray.length)
{
for(i=0;i<document.Form1.cities.options.length;i++)
{
document.Form1.cities.options[i]=null;
}
}
for(i=0;i<cityArray.length;i++)
{
document.Form1.cities.options[i]=new Option(cityArray[i][1],cityArray[i][0]);
}
}
function updateCities()
{
var selectedProvince=document.Form1.province.value;
alert(selectedProvince);
switch(selectedProvince){
case"":showCities(default1);break;
case"安徽":showCities(anhui);break;
case"北京":showCities(beijing);break;
}
}
[ 本帖最后由 ailinjie2007 于 2010-4-22 00:04 编辑 ]