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

js method to locate an anchor point

高洛峰
高洛峰Original
2016-12-06 13:55:351082browse

The anchor point can be set in the html page, and the anchor point definition

Html code

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

Anchor point use

Html code

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

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

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

How to jump to (locate) a fixed anchor point

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

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

After testing: hash will only jump to the first page of this page It works once, refreshing this page again will not work and href always works


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