我想拆分和连接两种类型的网址。例如
网址 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/