从URL中删除参数

JavaScript remove parameter from URL

本文关键字:参数 删除 URL      更新时间:2023-09-26

我想从URL中删除参数。我有这个URL http://localhost/?page=test&id=190603|190629

<button onclick="removeId(190603)">Remove ID</button>
<button onclick="removeId(190629)">Remove ID</button>

如何做,当点击按钮,id从url地址和重载地址没有id我已经删除?

试着…(这是以前版本的问题)

s=location.search||$('tag').text();
m=s.match(/id=(['d|]*)/);
if(m && m[1] && m[1].indexOf('|')>-1)
m[1].split('|').forEach(function(e){
document.write('<a href=http://localhost/?page=test&id='+s.replace(new RegExp('(^|[|])'+e+'(?=$|[|])'),'')+'">Remove '+e+' id from url</a><br>')
});
//else document.write('nop!')
document.write('<hr>');
// single id test:
s='?page=test&id=190603'
m=s.match(/id=(['d|]*)/);
if(m && m[1] && m[1].indexOf('|')>-1)
m[1].split('|').forEach(function(e){
document.write('<a href=http://localhost/?page=test&id='+s.replace(new RegExp('(^|[|])'+e+'(?=$|[|])'),'')+'">Remove '+e+' id from url</a><br>')
});
else document.write('nop!')
document.write('<hr>');
// no id test:
s='?page=test'
m=s.match(/id=(['d|]*)/);
if(m && m[1] && m[1].indexOf('|')>-1)
m[1].split('|').forEach(function(e){
document.write('<a href=http://localhost/?page=test&id='+s.replace(new RegExp('(^|[|])'+e+'(?=$|[|])'),'')+'">Remove '+e+' id from url</a><br>')
});
else document.write('nop!')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
location.search=<tag color="red">?page=test&amp;id=190603|764583|87436835|846345</tag><br>

好了,我睡了一会儿。

在php
上做同样的事情。