两个静态下拉框固定值实现简单联动!

来源:互联网 发布:海淀区苏州街淘宝兼职 编辑:程序博客网 时间:2024/04/29 22:07

今天这破玩艺耽误了半天,想了想,实在是傻到头了!贴出来为初级程序员做个参考

 

<select name="reportsendtype" id="reportsendtype" onchange="findpst()">
    <option value="2">自取</option>
    <option value="1" selected="selected">统一</option>
    <option value="3">快递</option>
</select>

 

<select name="reportsendpaytype" id="reportsendpaytype">
    <option value="2">企业付费</option>
    <option value="1" selected="selected">自费</option>
    <option value="0">无</option>
</select>

 

<script type="text/javascript">

function findpst(){
  alert(document.getElementById("reportsendtype").value);
  if(document.getElementById("reportsendtype").value == 2){
   var aaa = document.getElementById("reportsendpaytype");
   for(var i=0;i<aaa.options.length;i++){
    if(aaa.options[i].value == 0){
     aaa.options[i].selected='selected';
     break;
    }
   }
  }
 }
 </SCRIPT>

 

当reportsendtype选择"自取"时,reportsendpaytype的默认选项由"自费"变成"无",就这么简单,不用AJAX,只用几句JS代码就可实现!

 

 

原创粉丝点击