日期:2014-05-16  浏览次数:20320 次

怎么说我没定义sheng这个函数呢。。。

<!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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>二级互联菜单</title>
</head>
<body> 
<script type="text/javascript">
var provinces=document.getElementById("pro").options.length;
var province=new Array(provinces);
for(var i=0;i<provinces;i++)
province[i]=new Array();

province[0][0]=new Option("请选择","请选择");

province[1][0]=new Option("郑州","郑州");
province[1][1]=new Option("商丘","商丘");
province[1][2]=new Option("开封","开封");
province[1][3]=new Option("洛阳","洛阳");
province[1][4]=new Option("新乡","新乡");
province[1][5]=new Option("安阳","安阳");
province[1][6]=new Option("信阳","信阳");

province[2][0]=new Option("沈阳","沈阳");
province[2][1]=new Option("大连","大连");
province[2][2]=new Option("锦州","锦州");
province[2][3]=new Option("鞍山","鞍山");
province[2][4]=new Option("朝阳","朝阳");
province[2][5]=new Option("抚顺","抚顺");
province[2][6]=new Option("铁岭","铁岭");

province[3][0]=new Option("北京","北京");
province[3][1]=new Option("上海","上海");
province[3][2]=new Option("天津","天津");
province[3][3]=new Option("重庆","重庆");

var y=document.getElementById("city");
  function sheng(x){
  for(var i=1;i<y.options.length;i++){
  y.options[i]=null;
  }
  for(var j=0;j<province[x].length;j++){
  y.options[j]=new Option(province[x][j].text,province[x][j].value);
  }
  y.options[0].selected=true;
  }
</script>

<select id="pro" name="pro" onchange="sheng(this.options.selectedIndex)">
<option value="请选择">请选择</option>
<option value="河南" >河南</option>
<option value="辽宁" >辽宁</option>
<option value="直辖市">直辖市</option>
</select>
<select id="city" name="city">
<option value="请选择">请选择</option>
</select>
</body>
</html>

------解决方案--------------------
有几个错
1.<html>标签有两个
2.中文分号
3.document.getElementById在html前执行了,获取不到dom,会出错
一下是修改后的:
HTML code

<!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>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>二级互联菜单</title>
</head>
<body>  
<script type="text/javascript">
var provinces=document.getElementById("pro").options.length;
var province=new Array(provinces);
for(var i=0;i<provinces;i++)
province[i]=new Array();

province[0][0]=new Option("请选择","请选择");

province[1][0]=new Option("郑州","郑州");
province[1][1]=new Option(