根据选择选项使用jQuery更新或替换URL参数 [英] Update or replace URL parameters using jquery based on select option

查看:37
本文介绍了根据选择选项使用jQuery更新或替换URL参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个用于卖家,技能和城市的选择框

I have 3 select box for seller,skills and city

对于卖方

<select data-placeholder="Select Seller..." class="sellereselect"> 
   <option>test1</option>
   <option>test2</option>
   <option>test3</option>
   <option>test4</option>
</select>

关于技能

<select data-placeholder="Select skills..." class="sellereselect"> 
   <option>test1</option>
   <option>test2</option>
   <option>test3</option>
   <option>test4</option>
</select>

城市

<select data-placeholder="Select city..." class="sellereselect"> 
   <option>test1</option>
   <option>test2</option>
   <option>test3</option>
   <option>test4</option>
</select>

我想选择除url以外的任何卖方重定向到

I want if any one select seller than url redirect to

www.test.com/?seller=test1

如果有任何选择的卖家和城市而不是网址,则重定向到

If any one select seller and city than url redirect to

www.test.com/?seller=test1&skills=test1

如果参数已经存在于url中,则它将更新参数中的值.

if parameters already in url than it will update value in parameters.

我已经尝试了大多数事情,例如窗口替换,更改选择框的事件,但是没有任何帮助!请任何人帮我!!

I have tried most things like window replace, changes event for select box but nothing help me!! please any one help me !!

推荐答案

选中

$('.sellereselect').change(function(){
      
      var url = "http://www.test.com/?";
      
      if($("#seller").val()!='Select')
        url+='seller='+encodeURIComponent($("#seller").val())+'&';
      
      if($("#skill").val()!='Select')
        url+='skill='+encodeURIComponent($("#skill").val())+'&';
      
      if($("#city").val()!='Select')
        url+='city='+encodeURIComponent($("#city").val());
      
      url = url.replace(/\&$/,'');
      alert(url);
      window.location.href=url;
      
      });



   

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<select id="seller" data-placeholder="Select Seller..." class="sellereselect"> 
      <option>Select</option>
       <option value="test1&1">test1&1</option>
       <option value="test2">test2</option>
       <option value="test3">test3</option>
       <option value="test4">test4</option>
    </select>

    <select id="skill" data-placeholder="Select Seller..." class="sellereselect"> 
       <option>Select</option>
       <option value="test1">test1</option>
       <option value="test2">test2</option>
       <option value="test3">test3</option>
       <option value="test4">test4</option>
    </select>

    <select id="city" data-placeholder="Select Seller..." class="sellereselect"> 
       <option>Select</option>
       <option value="test1">test1</option>
       <option value="test2">test2</option>
       <option value="test3">test3</option>
       <option value="test4">test4</option>
    </select>

这篇关于根据选择选项使用jQuery更新或替换URL参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆