Home > Web Front-end > JS Tutorial > body text

js method to locate an anchor point

高洛峰
Release: 2016-12-06 13:55:35
Original
1057 people have browsed it

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

Html code

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

Anchor point use

Html code

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

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


Related labels:
js
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