HTML锚标记-href问题 [英] HTML anchor tag - href issue

查看:98
本文介绍了HTML锚标记-href问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


有什么区别
< a href ="javascript://">

< a href =#">

what is the difference between

<a href="javascript://">
and
<a href="#">

推荐答案

如果您可以使用一个有意义的实际URL作为HREF.

如果有人在您的链接上单击鼠标中键以打开新标签或禁用了JavaScript,则onclick不会触发.

如果那是不可能的,那么您至少应使用javascript和适当的click事件处理程序将锚标记注入文档中.

这并非总是可能的,但是在开发任何公共网站时都应努力做到这一点.


< a href =#">是标准的现代方式,坚持下去.
If you can have an actual URL that makes sense use that as the HREF.

The onclick won''t fire if someone middle-clicks on your link to open a new tab or if they have javascript disabled.

If that is not possible, then you should at least inject the anchor tag into the document with javascript and the appropriate click event handlers.

This isn''t always possible, but it should be striven for in developing any public website.


<a href="#"> is the standard modern way, stick with it.


这篇关于HTML锚标记-href问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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