< a href =“?”的理想值>>当用于JS事件? [英] Ideal value for <a href="?"> when used for a JS event?

查看:126
本文介绍了< a href =“?”的理想值>>当用于JS事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想要在我的网页上显示的链接,

I've got a link I want to appear on my page,

 <a>add another</a>

但它不会像链接一样,除非我添加一个 href 属性。我将使用jquery为它添加一个 .click()事件,所以它不需要其他任何东西。

But it doesn't look like a link unless I add an href attribute. I'm going to be using jquery to add a .click() event to it, so it doesn't really need anything else.

对于 href to的最佳值是多少? 的javascript:无效(0)?我担心如果有人在 .click()事件被添加或之前点击它, 会将它们滚动到页面顶部, void(0)看起来有点令人讨厌,并且不会提供信息if他们看地址栏...

What's the best value to href to? #? javascript:void(0)? My concern is if someone clicks it before the .click() event gets added or something. # will scroll them to the top of the page, void(0) looks kinda nasty and isn't informative if they look at the address bar...

推荐答案

我通常这样做...

<a href="JavascriptDisabled.htm">Foo</a>

然后在处理click事件时,确保取消它(通过返回false或调用preventDefault )。

And then when you handle the click event, make sure to cancel it (by returning false or calling preventDefault).

JavascriptDisabled.htm页面上只有一个友好的信息,例如您必须启用Javascript才能使用此功能。

The JavascriptDisabled.htm page just has a friendly message on it like "You must have Javascript enabled to use this feature".

这篇关于&lt; a href =“?”的理想值&gt;&gt;当用于JS事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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