jQuery:检测cmd +点击/控制+点击 [英] jQuery: detecting cmd+click / control+click

查看:219
本文介绍了jQuery:检测cmd +点击/控制+点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有标签中的我的网络应用程序的选项。

i have the options of my web application in tabs.

<ul id="tabs">
    <li><a href="a.php">aaa</a></li>
    <li><a href="b.php">bbb</a></li>
    <li><a href="c.php">ccc</a></li>
    <li><a href="d.php">ddd</a></li>
    <li><a href="e.php">eee</a></li>
</ul>

当用户点击任何选项卡(在同一个窗口中)时,会有一个淡出效果,使用此代码,然后自动重定向:

When the user clicks on any tab (in the same window) there is a fadeout effect which i get with this code, and afterwards an automatic redirection:

$('ul#tabs li a').click(function(e){
    if(e.which == 1) {
        var link = $(this).attr('href');
        $('#content').fadeOut('fast',function(){
            window.location = link;
        });
    }
});

它工作得很好,因为它忽略鼠标中间单击(当在新选项卡中打开选项时,效果不应该被触发)。问题是,如果我用键盘+鼠标组合打开标签,而不是打开一个新标签,它会触发整个效果/重定向代码。

It works great, because it ignores the mouse middle click (when opening the option in a new tab, the effect should not be triggered). The problem is that, if i open the tab with a keyboard+mouse combination, instead of opening a new tab, it triggers the whole effect/redirect code.

我如何用jQuery检测这个:

So, how can i detect this with jQuery:


  • cmd +鼠标左键(mac)

  • +鼠标左键(windows / linux)

推荐答案

metaKey评估为true?如果是,你就是。

In your click function, does e.metaKey evaluate to true? If so, there you are.

这篇关于jQuery:检测cmd +点击/控制+点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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