Go to #div box JavaScript

爷,独闯天下 提交于 2019-12-28 06:49:59

问题


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..

Wikipedia have it.. http://en.wikipedia.org/wiki/USA The links in the "Contents".. when you click you get to it..


回答1:


That's not Javascript, those are anchor links. See: 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:

<h1 id="FAQ">FAQs</h1>



回答2:


First, add an id to the HTML element. This will serve as the anchor.

For example:

id="mybox"

Now simply add a link to #mybox on that page. E.g. 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.



来源:https://stackoverflow.com/questions/2255388/go-to-div-box-javascript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!