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

js method to locate an anchor point

高洛峰
Release: 2017-01-04 17:42:58
Original
1544 people have browsed it

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

Html code

<a name="firstAnchor">&nsbp;</a>
Copy after login


Anchor point usage

Html code

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


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!


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template