为什么href ="#"用于项目? [英] Why href="#" is used in projects?

查看:86
本文介绍了为什么href ="#"用于项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在许多网站上,我看到有href =#的链接。这是什么意思?它的用途是什么?



我尝试过:



i搜索了许多网站,但无法理解其含义。

On many websites I see links that have href="#". What does it mean? What is it used for?

What I have tried:

i searched many sites, but cant understand the meaning.

推荐答案

以#开头的HREF是页面内的一个链接 - 通常是一个部分头部。 />
如果它是独立的,没有要链接到DIV的ID的文本,则表示页面顶部。

该页面将滚动,以便链接目的地可见。
An HREF starting with '#' is a link within the page - to a section head, normally.
If it's on it's own, with no text to ID the DIV to link to, it means "top of page".
The page will scroll so that the link destination is visible.


它基本上意味着导航到此页面上的某个位置,换句话说就是留在这里。这是一种制作一个不会去任何地方的链接的方法,并且当你想使用javascript来处理链接的点击事件而不是浏览器导航时使用它,但是要将标记视为它需要的链接。 href所以#使它成为一个无处可去的链接。这也意味着如果javascript被禁用,如果用户点击链接就不会发生任何不良事件,它什么都不做。



要详细了解,#表示法是一个页面锚点。您可以使用锚名称命名页面的某些部分并导航到该部分页面,因此如果我有类似的链接; mypage.html#results和在mypage页面上有一个名为results的锚点



It basically means "navigate to a location on this page", or in other words "stay here". It's a way of making a link that doesn't go anywhere, and it's used when you want to use javascript to handle the click event of the link rather than browser navigation, however to consider the tag as being a link it needs something in the href so "#" makes it a link that goes nowhere. It also means that if javascript is disabled nothing untoward happens if the user clicks the link, it just does nothing.

To go into more detail, the "#" notation is a page anchor. You can "name" parts of the page and navigation to that part of the page using the anchor name, so if I have a link like; "mypage.html#results" and on mypage there is an anchor on the page called "results"

<a name="results">





然后点击该链接会将用户带到mypage并直接向下滚动到结果锚点。



then clicking on that link will take the user to mypage and scroll down directly to the results anchor.


这篇关于为什么href =&quot;#&quot;用于项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆