Javascript 删除url中的哈希符号及其后面的所有文本
如何删除URL的哈希符号及其后的文本 例如,URL是 我想删除整个内容文本Javascript 删除url中的哈希符号及其后面的所有文本,javascript,jquery,html,Javascript,Jquery,Html,如何删除URL的哈希符号及其后的文本 例如,URL是 我想删除整个内容文本 window.location.href.split('#')[0] 你可以试试看 我想这就是你要找的。。。(即,当您单击其href中包含哈希的超链接时,是否要删除该哈希并导航到剩余的URL?) $(“#someLink”)。单击(函数(e){ //阻止正常导航到href(包含哈希的完整URL) e、 预防默认值(); //导航到“/some_页面”(第一个“#”左侧的所有内容) document.locatio
window.location.href.split('#')[0]
你可以试试看 我想这就是你要找的。。。(即,当您单击其href中包含哈希的超链接时,是否要删除该哈希并导航到剩余的URL?)
$(“#someLink”)。单击(函数(e){
//阻止正常导航到href(包含哈希的完整URL)
e、 预防默认值();
//导航到“/some_页面”(第一个“#”左侧的所有内容)
document.location=this.href.split('#')[0];
});
document.location.hash=”“
,是的,它被称为“散列”。获取散列:,删除它:可能重复的代码不会删除散列。它只返回url,不返回hash.history.pushState(“”,document.title,window.location.pathname);
<!DOCTYPE html>
<html>
<body>
<a id="someLink" href="/some_page#some_hash">Click Me</a>
<script src="http://code.jquery.com/jquery-2.2.4.min.js"></script>
<script>
$('#someLink').click(function (e) {
// Prevent normal navigation to the href (the full URL with hash)
e.preventDefault();
// Navigate to "/some_page" (everything to left of the first "#")
document.location = this.href.split('#')[0];
});
</script>
</body>
</html>