PHP头部位置 - 移动到锚点而不重新加载 [英] PHP Header Location - Move to anchor without reloading
本文介绍了PHP头部位置 - 移动到锚点而不重新加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图想出一种方法来导航到同一页面内的HTML锚点而无需重新加载。现在我只是使用:
header(Location:#anchor_name);
问题在于它重新加载页面。我真的想尽量避免使用JavaScript,但我不知道是否有其他方法?
谢谢!
PS - 我知道我需要在重定向中使用完整的URI - 这里只是为了简单起见而省略。
您可以使用js:
函数scrollToAnchor_name(anchorName){
location.hash =#+ anchorName;
}
I'm trying to come up with a way to navigate to HTML anchors within the same page without reloading. Right now I'm just using:
header("Location: #anchor_name");
The problem with that is it reloads the page. I'd really like to avoid using JavaScript if I can but I don't know if there's any other way?
Thank you!
PS - I know I need to use the full URI in the redirect - just abbreviated here for simplicity.
解决方案
You could use js:
function scrollToAnchor_name(anchorName) {
location.hash = "#" + anchorName;
}
这篇关于PHP头部位置 - 移动到锚点而不重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文