Home  >  Article  >  Backend Development  >  请问有时候url最后有时候是#标志,请问这个字符有什么用吗?

请问有时候url最后有时候是#标志,请问这个字符有什么用吗?

WBOY
WBOYOriginal
2016-06-06 20:48:441149browse

比方说像这样的url http://segmentfault.com/ask/101# 最后有一个#字符,是有什么用处吗?

回复内容:

比方说像这样的url http://segmentfault.com/ask/101# 最后有一个#字符,是有什么用处吗?

这问题不问在101里吗?

#字符后边的内容,是指定让浏览器翻动到网页中的某个锚点标记,所指定的位置。这个位置,是在HTML标签<a></a>中定义的。

例如:很多网页有简易(非js)的“跳到正文 Skip to content”功能,做法就是在需要跳到的位置,这里是正文最顶端,加上<a name="articlestart"></a>

之后,如果在文章内部做链接就是<a href="#articlestart"></a>,点击后就会跳到正文开头。外部链接就是http://example.com/a.htm#articlestart,网页加载后就会跳到正文开头。

如果<a></a>的href属性是#开头的,那么点击链接后浏览器不会刷新跳转。但如果不给<a></a>赋href属性,则链接指上去没有手型箭头。所以有时也只用一个#,来做<a></a>标签链接的占位,达到链接只点击不跳转,而用javascript进一步处理的目的。这样的占位符也可能是javascript:void(0);一类的。

注意:#+锚点标签这部分内容,必须放在URL最后边,且不是HTTP Request的一部分,不会被发送到服务器端。例如http://example.com/1.php?a=1&b=2#anchor1,对服务器而言与http://example.com/1.php?a=1&b=2没有任何区别。

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