JQuery or [removed] How determine if shift key being pressed while clicking anchor tag hyperlink?

前端 未结 12 2063
别那么骄傲
别那么骄傲 2020-11-27 03:00

I have an anchor tag that calls a JavaScript function.

With or without JQuery how do I determine if the shift key is down while the link is clicked?

The foll

12条回答
  •  一个人的身影
    2020-11-27 03:38

    The excellent JavaScript library KeyboardJS handles all types of key presses including the SHIFT key. It even allows specifying key combinations such as first pressing CTRL+x and then a.

    KeyboardJS.on('shift', function() { ...handleDown... }, function() { ...handleUp... });
    

    If you want a simple version, head to the answer by @tonycoupland):

    var shiftHeld = false;
    $('#control').on('mousedown', function (e) { shiftHeld = e.shiftKey });
    

提交回复
热议问题