为什么主题标签用于achor链接的占位符?

j0s*_*h1e 4 html php get

我经常在其他网站和教程中看到,当锚具有更大的目的而不仅仅是一个链接时,它通常有一个hashtag(#)作为href属性的值.我正在我正在进行的项目中的列表中创建一系列列表,我很想自己这样做,但我担心这可能会使团队中的其他开发人员正在努力成为这个主题标签的系统复杂化单击后出现在地址栏中.

以这种方式排除href是否有缺点?我假设它不是由于这种方法的流行使用,但是标签可能会搞乱一个使用的函数GET吗?

Chr*_*ker 5

No worries,, the "hash tag" is fine to use, has been part of the standard for a decade, and doesn't affect GET. The "anchor tag" <a> is originally for this purpose.

You can use it to create "jump links" to skip to different parts of the document (anchors, as is used on the HTML specification doc pages themselves), or as a "hashbang" in combination with javascript.

What you should NOT do is use the <a> tag only to get a pointer cursor for no reason. That said, if the thing does something when you click it (usually why you put a pointer cursor on something), either by changing the hash, linking to a new document, or triggering a javascript function, there's no reason not to use an anchor tag, nor is it bad practice.

当你看到一个只有"#"as的锚时href,通常表明开发人员打算将javascript监听器应用于该元素.如果客户端没有可用的javascript,空锚将作为无操作回退.在这种情况下,用户单击链接并且没有任何反应.如果您正在使用渐进增强原则,那么您可能会在其中放置一个非javascript URI等效项.

文档