Html 转到 #div 框 JavaScript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2255388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Go to #div box JavaScript
提问by Karem
Maybe jQuery, maybe not, but how do i do so like when you click on a link eg. FAQ it goes to the FAQ div box? I mean if its on the bottom then you just click on that link and then it goes to it..
也许jQuery,也许不是,但是当您单击链接时,我该怎么做,例如。常见问题解答它转到常见问题解答 div 框?我的意思是,如果它在底部,那么您只需单击该链接,然后它就会转到它..
Wikipedia have it.. http://en.wikipedia.org/wiki/USAThe links in the "Contents".. when you click you get to it..
维基百科有它.. http://en.wikipedia.org/wiki/USA“目录”中的链接..当你点击你会得到它..
回答by Matt Brunmeier
That's not Javascript, those are anchor links. See: http://www.w3.org/TR/html401/struct/links.html
那不是 Javascript,那些是锚链接。见:http: //www.w3.org/TR/html401/struct/links.html
Basically, you'd link as such:
基本上,你会这样链接:
<a href="#FAQ">FAQ</a>
Then above the content you're linking to:
然后在您要链接的内容上方:
<a name="FAQ" />
Alternatively, you could use the same link and set the ID of the FAQ section header to "FAQ", like so:
或者,您可以使用相同的链接并将 FAQ 部分标题的 ID 设置为“FAQ”,如下所示:
<h1 id="FAQ">FAQs</h1>
回答by user258634
First, add an id to the HTML element. This will serve as the anchor.
首先,向 HTML 元素添加一个 id。这将作为锚点。
For example:
例如:
id="mybox"
Now simply add a link to #myboxon that page. E.g. example.com/index.html#mybox
现在只需在该页面上添加一个指向#mybox的链接。例如example.com/index.html#mybox
<a href="#mybox">Box</a>
As mentioned these are not anything to do with javascript; it is not required for this.
如前所述,这些与 javascript 无关;这不是必需的。