Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

html - How to navigate to a section of a page

I have a landing page with links. How can I direct user to a section of a different page?

Main Page:

<a href="/sample">Sushi</a>
<a href="/sample">BBQ</a>

Sample Page:

<div id='sushi'></div>
<div id='bbq'></div>

Clicking on "Sushi" or "BBQ" in the Main Page should navigate the user to the div with id sushi or bbq (respectively) of the page sample.

Is it possible without JQuery? I do not mind using JQuery but a simpler solution using html would work too.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use HTML's anchors:

Main Page:

<a href="sample.html#sushi">Sushi</a>
<a href="sample.html#bbq">BBQ</a>

Sample Page:

<div id='sushi'><a name='sushi'></a></div>
<div id='bbq'><a name='bbq'></a></div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...