首页 >web前端 >html教程 >级联问题,求解决!!!_html/css_WEB-ITnose

级联问题,求解决!!!_html/css_WEB-ITnose

WBOY
WBOY原创
2016-06-24 12:17:32840浏览

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <title>MyHtml.html</title>	    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">    <meta http-equiv="description" content="this is my page">    <meta http-equiv="content-type" content="text/html; charset=UTF-8">        <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->  </head>  <script type="text/javascript">  function selectshi(sheng){  	  var s = sheng.value;  	  var shi = document.getElementById("shi");  	  if(s == 'initial'){  	  	  shi.innerHTML = '<option>请选择市</option>';  	  }else if(s == 'bj'){  	  	  shi.innerHTML = '<option>朝阳区</option><option>海淀区</option>';  	    	  }else if(s == 'hb'){  	  	  shi.innerHTML = '<option>石家庄</option><option>张家界</option><option>保定</option>';    	  }else if(s == 'ln'){  	  	  shi.innerHTML = '<option>沈阳</option><option>大连</option><option>营口</option>';    	  }else if(s == 'hn'){  	  	  shi.innerHTML = '<option>郑州</option><option>洛阳</option><option>焦作</option>';    	  }else if(s == 'js'){  	  	  shi.innerHTML = '<option>南京</option><option>徐州</option><option>苏州</option>';    	  }  }  </script>  <body>        <select id="sheng" onchange="selectshi(this)">    <option value="initial">请选择省</option>    <option value="bj">北京市</option>    <option value="sd">山东省</option>    <option value="hb">河北省</option>    <option value="ln">辽宁省</option>    <option value="hn">河南省</option>    <option value="js">江苏省</option>    </select>    <select id="shi">    <option>请选择市</option>    </select><br>  </body></html>

选中了省之后,后边的市就成了空了


回复讨论(解决方案)

function selectshi(sheng){
var obj=document.getElementById("shi");
obj.options.length=0;
var s = sheng.value;
if(s == 'initial'){
obj.options.add(new Option('请选择市',''));
}else if(s=='bj'){
obj.options.add(new Option('朝阳区','cy'));
obj.options.add(new Option('海淀区','hd'));
}else if(s==hb){
obj.options.add(new Option('石家庄','sjz'));
obj.options.add(new Option('张家界','zjj'));
}else if(s=='ln'){
.....
}
}

或者:
<script> <br /> function selectshi(sheng){ <br /> var s = sheng.value; <br /> var addshi="<select id=shi>" <br /> if(s == 'initial'){ <br /> addshi = addshi+'<option>请选择市'; <br /> }else if(s == 'bj'){ <br /> addshi = addshi+'<option>朝阳区<option>海淀区'; <br /> }else if(s == 'hb'){ <br /> addshi = addshi+'<option>石家庄<option>张家界<option>保定'; <br /> }else if(s == 'ln'){ <br /> addshi = addshi+'<option>沈阳<option>大连<option>营口'; <br /> }else if(s == 'hn'){ <br /> // ...... <br /> } <br /> document.getElementById("addshi").innerHTML=addshi+"" <br /> } <br /> <br /> </script>   
 

         
      
 
 
 

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn