jQuery - 点击链接问题触发事件 [英] jQuery - Triggering Events from Clicking on a Link Issue
问题描述
我想触发一个事件,当一个链接被点击通常点击或通过打开它在一个新的标签(例如,中间点击,ctrl +点击等)
I'd like to trigger an event when a link is clicked both by clicking on it normally or by opening it in a new tab (e.g., middle click, ctrl + click, etc)
我已经尝试了以下目录:
I've tried the following so far:
$('a')。click(myfunc) code>不捕获中间点击。
$('a').click(myfunc)
Doesn't capture middle clicks.
$('a')。mousedown(myfunc)
工作,但似乎是阻止链接被跟随,即使我的功能不调用 event.preventDefault
。
$('a').mousedown(myfunc)
works, but it seems to be preventing the link from being followed even though my function doesn't call event.preventDefault
.
任何想法如何做?
推荐答案
尝试从您的处理程序返回 true 功能。返回任何内容都不能被浏览器解释为无效返回,从而防止执行默认操作。
Try returning true from your handler function. Returning nothing can be interpreted by the browser as a void return and thus prevent the default action from being carried out.
这篇关于jQuery - 点击链接问题触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!