如何检查像“shift”这样的键盘修饰符点击处理程序? [英] How to check for keyboard modifiers like "shift" on click handler?

查看:76
本文介绍了如何检查像“shift”这样的键盘修饰符点击处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用jQuery 单击事件时,我会检查传递给click处理程序的事件对象,以确定用户是否持有 shift 点击时键。

When using a jQuery click event, I would would check the event object that is passed to the click handler to determine if the user was holding the shift key when they clicked.

在KnockoutJS中使用点击装订时,是否可以检查键盘修改器,如shift键?如果是这样,怎么做?

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

推荐答案

在当前的Knockout代码中,click绑定实际上是传递给jQuery事件对象的。这个对象有shiftKey,altKey和ctrlKey。

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

因此,你的点击绑定绑定的函数可能如下所示:

So, the function that your click binding is bound to could look like:

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

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

以下是一个示例: http://jsfiddle.net/rniemeyer/ak4vL/

如果您传递给点击装订的功能是匿名的,那么您可以这样写:

If the function that you are passing to your click binding is anonymous, then you can write it like:

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

如下例所示: http://jsfiddle.net/rniemeyer/YUhzk/

这篇关于如何检查像“shift”这样的键盘修饰符点击处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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