Php 从url中删除路径并添加另一个路径

Php 从url中删除路径并添加另一个路径,php,javascript,url,path,onclick,Php,Javascript,Url,Path,Onclick,我有一个包含链接(动态)的div,当用户单击链接时,希望从href attrybute中删除路径并添加另一个路径 例如:我想将其转换为: <div id="example"> <a href="/some path/page_id=8">Link1</a> <a href="/some path/page_id=8">Link2</a> <a href="/some path/page_id=8">Link3</a&

我有一个包含链接(动态)的div,当用户单击链接时,希望从href attrybute中删除路径并添加另一个路径

例如:我想将其转换为:

<div id="example"> 
<a href="/some path/page_id=8">Link1</a>
<a href="/some path/page_id=8">Link2</a>
<a href="/some path/page_id=8">Link3</a>
......

</div>

......
致:


......
我是php和javascript的高手,因此非常感谢您的帮助

谢谢

这应该适合您(假设您有jQuery)


编辑

如果您需要本机JavaScript版本,请点击这里

var e = document.getElementById('example');
var links = e.getElementsByTagName('a');

for(x in links){
    links[x].onclick = function(){
        this.href = this.href.replace('/some%20path', '/some%20path/ANOTHER_PATH');
    };
}

这应该适合您(假设您有jQuery)


编辑

如果您需要本机JavaScript版本,请点击这里

var e = document.getElementById('example');
var links = e.getElementsByTagName('a');

for(x in links){
    links[x].onclick = function(){
        this.href = this.href.replace('/some%20path', '/some%20path/ANOTHER_PATH');
    };
}

纯JS:

document.getElementById('example').childNodes[1].href = 'www.najdi.si';
document.getElementById('example').childNodes[2].href = 'www.google.com'; 
纯JS:

document.getElementById('example').childNodes[1].href = 'www.najdi.si';
document.getElementById('example').childNodes[2].href = 'www.google.com'; 

使用jquery:
$('#link')。单击(函数(){change your path})或者您可以使用javascript window.location.Replace(something\u str,with\u something\u else\u str);在php中,您可以调用header(位置:'new-path');好的,但是如何做动态…我的意思是从到单击更改的所有链接。对不起,我的英文是jquery:
$('#link')。单击(function(){change your path})或者您可以使用javascript window.location.Replace(something\u str,with\u something\u else\u str);在php中,您可以调用header(位置:'new-path');好的,但如何动态操作…我的意思是从到单击p.s.更改的所有链接。对不起,我的英语回答很好-只是对OP的一个注释,它需要javascript库。@nickb,我也添加了一个本地javascript版本:)回答很好-只是对OP的一个注释,它需要javascript库。@nickb,我还添加了一个本地JavaScript版本:)