jQuery: detecting cmd+click / control+click

后端 未结 5 2238
Happy的楠姐
Happy的楠姐 2021-02-18 17:31

i have the options of my web application in tabs.

5条回答
  •  情话喂你
    2021-02-18 18:12

    According to MDN, the event.metaKey returns true for the command key on Mac keyboards and returns true for windows keys on the Windows keyboards.

    So, you should also check the ctrlKey property to detect the control key.

    if (event.ctrlKey || event.metaKey) {
        //ctrlKey to detect ctrl + click
        //metaKey to detect command + click on MacOS
        yourCommandKeyFunction();
    } else {
        yourNormalFunction();
    }
    

提交回复
热议问题