我需要解决方案在url中找到hashtag并使用php追加到该url中的last。
旧网址: http://www.example.com?q=123123#anchor1?name=shreyas&city=surat
新网址 http://www.example.com?q=123123&name=shreyas&city=surat#anchor1
答案 0 :(得分:1)
var url = 'http://www.example.com#anchor1?name=shreyas&city=surat';
var hash = /#[^?]+/.exec(url)[0];
url = url.replace(hash, '') + hash;
答案 1 :(得分:0)
您也可以试试这个。
HTML:
<a href="http://www.example.com#anchor1?name=shreyas&city=surat">My Url</a>
jQuery:
var url= $("a").attr("href");
//get the subString matching that pattern "#...?"
var subUrl = url.match("\#[A-Z]*[a-z]*[0-9]*");
// removes the subString that matches the pattern "#...?"
url= url.replace(/\#[A-Z]*[a-z]*[0-9]*/, '');
//final url
url= url+ subUrl;
//updating it
$("a").attr("href", url);