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

前端 未结 12 2033
别那么骄傲
别那么骄傲 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:40

    A more modular approach plus the ability to keep your this scope in the listeners:

    var checkShift = function(fn, self) {
      return function(event) {
        if (event.shiftKey) {
          fn.call(self, event);
        }
        return true;
      };
    };
    
    $(document).on('keydown', checkShift(this.enterMode, this));
    

提交回复
热议问题