[英]Select2 onchange select option then append or strip url depending on option
Currently I have a select
dropdown filter setup via php like this: 目前,我有一个通过php的
select
下拉过滤器设置,如下所示:
<?php if($this->config->get("config_show_tmall_only")){?>
<?php if(isset($code) && $code=="tmall"){?>
<select id="tmallFilter">
<option value="&code=tmall">Tmall only</option>
<option value="">Taobao & Tmall</option>
</select>
<?php }else{?>
<select id="tmallFilter">
<option value="">Taobao & Tmall</option>
<option value="&code=tmall">Tmall only</option>
</select>
<?php }?>
<?php }?>
It detects if &code=tmall
is in the url and runs the first block 它检测
&code=tmall
是否在url中并运行第一个块
I am appending &code=tmall
through this script that runs exactly how I need 我正在通过完全按照我的需要运行的脚本添加
&code=tmall
$('#tmallFilter').bind('change', function () {
var brwsr_url=document.URL;
var redirecturl= brwsr_url + $(this).val();
location.href = redirecturl;
});
The problem I am running into is when i need to go back to Taobao & Tmall
I can only add to the url, not strip characters based on that select. 我遇到的问题是,当我需要返回
Taobao & Tmall
我只能添加到url,而不能基于该选择删除字符。
Is there any way I can strip &code=tmall
from the url when I select the Taobao & Tmall
当我选择
Taobao & Tmall
时,有什么方法可以从网址中删除&code=tmall
Taobao & Tmall
Taobao & Tmall
option? Taobao & Tmall
选项?
This is to strip away &code=tmall
specifically using String.replace
: 这是专门使用
String.replace
剥离&code=tmall
String.replace
:
$('#tmallFilter').bind('change', function () {
var brwsr_url = document.URL;
var redirecturl= brwsr_url.replace(/&code=tmall/, '') + $(this).val();
location.href = redirecturl;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.