【发布时间】:2016-10-10 18:46:12
【问题描述】:
【问题讨论】:
-
document.location.hash = "",是的,它被称为“哈希”。
标签: javascript jquery html
【问题讨论】:
document.location.hash = "",是的,它被称为“哈希”。
标签: javascript jquery html
window.location.href.split('#')[0]
你可以试试!
【讨论】:
我认为这就是您要查找的内容...(即,当您单击其 href 中包含哈希的超链接时,您想去掉哈希并导航到剩余的 URL?)
<!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>
【讨论】: