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

急!如何php用js实现联动时间选择框。
要求实现当选择下拉框选择类型为月时,显示<div id="month_select">的内容,当类型为年时只显示
<div id="year_select">的内容。部分代码为:

<select name="viewtype" onChange="selects(this.value)">
  <option selected value="month">月</option>
  <option value="year" selected>年</option>
</select>

<div id="myselect"></div><br><br>
<div style= "display:none; "> 
  <div id="year_select">
<select id="year" name="year">
  <option value="" selected>请选择</option>
  <script>for(i=2000;i<=2020;i++)document.write("<option>"+i+"</option>")</script>
  </select><label>年</label>
  </div>  
  <div id="month_select">
<select id="year" name="year">
  <option value="" selected>请选择</option>
  <script>for(i=2000;i<=2020;i++)document.write("<option>"+i+"</option>")</script>
  </select><label>年</label>
  <select id="month" name="month">
  <option value="" selected>请选择</option>
  <script>for(i=1;i<=12;i++)document.write("<option>"+i+"</option>")</script>
  </select><label>月</label>
  </div>  
</div>
   
<script type="text/javascript">
  <!--
function selects(types){
method = "GET";
  (!!!!!该添加的js内容;)
}
//-->
</script>

------解决方案--------------------
<select name="viewtype" onChange="selects(this.value)">
<option selected value="month">月</option>
<option value="season">季度</option>
<option value="year">年</option>
</select>

 
<script type="text/javascript">
<!--
function selects(types){
method = "GET";
if (types=="year"){
xsid="year_select";
ycid="month_select";
zcid="season_select";
}else if(types=="season"){
xsid="season_select";
ycid="month_select";
zcid="year_select";
}else
{
xsid="month_select";
ycid="year_select";
zcid="season_select";
}
document.getElementById(xsid).style.display="";
document.getElementById(ycid).style.display="none";
document.getElementById(zcid).style.display="none";
}
//-->
</script>