Home  >  Article  >  Web Front-end  >  js method to locate an anchor point

js method to locate an anchor point

高洛峰
高洛峰Original
2017-01-04 17:42:581493browse

You can set anchor points in the html page, and the anchor point definition

Html code

<a name="firstAnchor">&nsbp;</a>


Anchor point usage

Html code

<a href="#firstAnchor">跳至第一个锚点</a>


But for js, how to jump to a fixed anchor point on the page after completing an operation in js

location.href in js You can jump to a certain url;

How to jump to (locate to) a fixed anchor point

1. location.href = "#firstAnchor"; // firstAnchor is the anchor point Name

2, window.location.hash = "#firstAnchor"; // firstAnchor is the anchor name

After testing: the hash will only be used after the first jump to this page. Function, refreshing this page again will not work, and href will always work

The above js method to locate an anchor point is all the content shared by the editor. I hope it can give you a For reference, I also hope that everyone will support the PHP Chinese website.

For more js related articles on how to locate an anchor point, please pay attention to the PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn