最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery - Triggering Events from Clicking on a Link Issue - Stack Overflow

programmeradmin2浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 6

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.

发布评论

评论列表(0)

  1. 暂无评论