省市

<!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>
<script type="text/javascript">
  var province=new Array({"湖北省":["孝感市","武汉市","天门市"],"湖南省":["长沙市","韶山市","岳阳市"]}); //{}对象 ,属性名:属性值
 function ShowProvince(){
alert(province.length);
alert(province[0]["湖北省"].length);
 for( key  in province[0]  )
 {
 alert(key);  
  }
 for(i=0;i<province[0]["湖北省"].length;i++){
 var proOp=new Option(province[i],province[0][i]);
 
 }
  }
  
/*  var province=new Array("湖北省","湖南省");
  // var province =["湖北省","湖南省"]; 
   province["湖北省"]=new Array("孝感市","武汉市","天门市");
   province["湖南省"]=new Array("长沙市","韶山市","岳阳市");
   function ShowProvince(){
//  alert("1");
  for(i=0;i<province.length;i++){
  var proOp=new Option(province[i],province[i]);
  document.getElementById("pro").options.add(proOp);
  } 
   }
   
   function ShowCity(){
  var pro=document.getElementById("pro").value;
  document.getElementById("city").length=0;
  for(i=0;i<province[pro].length;i++){
  var cityOp=new Option(province[pro][i],province[pro][i]);
  document.getElementById("city").options.add(cityOp);
  }
   }
     */
   
</script>
</head>
    
<body onload="ShowProvince()">
省:
<select id="pro" onchange="ShowCity()">
</select>
市:
<select id="city">
</select>
</body>
</html>

posted on 2016-07-08 17:00  博客LYF  阅读(228)  评论(0编辑  收藏  举报

导航