admin管理员组文章数量:1415119
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)
Doesn't capture middle clicks.
$('a').mousedown(myfunc)
works, but it seems to be preventing the link from being followed even though my function doesn't call event.preventDefault
.
Any ideas how to do this then?
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)
Doesn't capture middle clicks.
$('a').mousedown(myfunc)
works, but it seems to be preventing the link from being followed even though my function doesn't call event.preventDefault
.
Any ideas how to do this then?
Share Improve this question edited Sep 13, 2015 at 9:29 Kristijan Iliev 4,99710 gold badges30 silver badges51 bronze badges asked Sep 29, 2008 at 1:59 GregGreg 47.2k91 gold badges237 silver badges298 bronze badges1 Answer
Reset to default 6Try 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.
本文标签: javascriptjQueryTriggering Events from Clicking on a Link IssueStack Overflow
版权声明:本文标题:javascript - jQuery - Triggering Events from Clicking on a Link Issue - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745225250a2648575.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论