javascript - 使用 jQuery 删除匹配词

标签 javascript jquery

我想拆分和连接两种类型的网址。例如
网址 1:
http://localhost/site/index.php?route=product/category&path=20&sort=p.price&order=ASC&order=DESC
网址 2:
http://localhost/site/index.php?route=product/category&path=20&limit=8

<input type="hidden" class="sort" value="http://localhost/site/index.php?route=product/category&path=20&sort=p.price&order=ASC&order=DESC" />

<input type="hidden" class="limit" value="http://localhost/site/index.php?route=product/category&path=20&limit=8" />

我想加入查询字符串但删除重复项。

我终于在寻找这个结果

http://localhost/site/index.php?route=product/category&path=20&sort=p.price&order=ASC&order=DESC&limit=8

最佳答案

var getUrlParameter = function getUrlParameter(sParam, url) {
    var sPageURL = decodeURIComponent(url),
        sURLVariables = sPageURL.split('&'),
        sParameterName,
        i;

    for (i = 0; i < sURLVariables.length; i++) {
        sParameterName = sURLVariables[i].split('=');

        if (sParameterName[0] === sParam) {
            return sParameterName[1] === undefined ? true : sParameterName[1];
        }
    }
};

现在读取各个参数

var order = getUrlParameter('order', 'http://localhost/site/index.php?route=product/category&path=20&sort=p.price&order=ASC&order=DESC');
var limit = getUrlParameter('limit', 'http://localhost/site/index.php?route=product/category&path=20&limit=8');

并使用参数创建一个新的 url。

关于javascript - 使用 jQuery 删除匹配词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38674509/

相关文章:

javascript - V8: console.log 实现

javascript - PHP,CSS,JavaScript : click on image -> change the image -> call function

jquery - 基于动画 jQuery 滚动的图像变化

javascript - 可调整大小的 div 不在包含参数内

javascript - Angular 7 : How to access/send only body part of HTTP Response from test case

javascript - Javascript 是否按顺序运行代码行?并完成处理然后继续?

php - 克隆后动态下拉中断

jquery - 如何实现一组 Div 元素之间的碰撞检测?

javascript - 如何获取窗口 "right"?

java - 使用 Apache Ant 构建 PhoneGap 应用程序