dsfdsfdsfdsf1223 2010-07-30 13:18
浏览 7
已采纳

在所有下拉列表的更改事件中,将所有下拉列表中的选定值放入url params中?

I have three drop downs in mypage.php:

<select name='vehicle'>
  <option value=''>Select</option>
  <option value='bus'>Bus</option>
  <option value='bike'>Bike</option>
  <option value='car'>Car</option>
</select>

<select name='color'>
  <option value=''>Select</option>
  <option value='red'>Red</option>
  <option value='blue'>Blue</option>
  <option value='green'>Green</option>
</select>

<select name='cities'>
  <option value=''>Select</option>
  <option value='newyork'>New York</option>
  <option value='london'>London</option>
  <option value='paris'>Paris</option>
</select>

When I open page first time then in all dropdown 'Selected' option is selected.

Question:

When I select Bus from vehicle dropdown then url should be:

mypage.php?vehicle=bus

Then when I select Red from color dropdown then url should be:

mypage.php?vehicle=bus&color=red

Then when I select Paris from cities dropdown then url should be:

mypage.php?vehicle=bus&color=red&city=paris

Then I again select Car from vehicle then url should be:

mypage.php?vehicle=car&color=red&city=paris
  • 写回答

2条回答 默认 最新

  • dtmm0148603 2010-07-30 13:25
    关注

    Are you using a particular js framework? This behaviour is the standard form submit behaviour. You need to submit the form as a GET request in order to put the params in the actual URL, but as I say, any form submit will achieve this by default as that's the way GET form submits work.

    In jQuery for instance you can trigger a form submit on select change using:

    $(function(){
      $("#someFormId select").change(function(){
        $("#someFormId").submit();
      }
    });
    

    You form would be something like:

    <form id="someFormId" name="myForm" action="/some/action" method="GET"> ... </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算