How to check keyboard modifiers like shift on click handler?

When using the jQuery event, clickI would check the event object that is passed to the click handler to determine if the user held the key shiftwhen pressed.

Is it possible to check keyboard modifiers like shift key when using click binding in KnockoutJS? If so, how?

+3
source share
2 answers

In current Knockout code, the click binding is actually passed to the jQuery event object. This object has shiftKey, altKey and ctrlKey.

So, the function that the click binding is bound to might look like this:

click: function (event) {if (event.shiftKey) {do something (); }}

: http://jsfiddle.net/rniemeyer/ak4vL/

, , , :

<button data-bind="click: function(event) { viewModel.click(event); }">More Hide Anonymous Function</button>

: http://jsfiddle.net/rniemeyer/YUhzk/

+5

javascript, , knockoutjs click, , - :

 e.shiftKey
 e.altKey
 e.ctrlKey
0

Source: https://habr.com/ru/post/1796509/


All Articles