我想從URL中刪除參數。 我有這個URL http://localhost/?page=test&id=190603|190629JavaScript從URL中刪除參數
<button onclick="removeId(190603)">Remove ID</button>
<button onclick="removeId(190629)">Remove ID</button>
怎麼辦時,該ID從URL地址刪除點擊按鈕,並刷新沒有ID地址我已經刪除?
我想從URL中刪除參數。 我有這個URL http://localhost/?page=test&id=190603|190629JavaScript從URL中刪除參數
<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&id=190603|764583|87436835|846345</tag><br>
好了,我得到了一些lulz。
哎,並回答了更新的問題:製作相同(如上)的東西上php
嗯......什麼? '當你想刪除它? – Dimava
看起來你已經忘記包含[你試過的] [http://whathaveyoutried.com]的[mcve]以及你正在掙扎的東西。因此,這個問題是[題外話(#1)](/幫助/話題)。 – zzzzBov
這個不清楚。點擊你想刪除ID或190629替換ID 190603?刷新頁面是什麼意思? – derloopkat