Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Knockout.js div或Section上的按键事件_Knockout.js - Fatal编程技术网

Knockout.js div或Section上的按键事件

Knockout.js div或Section上的按键事件,knockout.js,Knockout.js,附加按键事件: 我的视图模型: Billing.BillingViewModel = function () { this.showSearcherCustomerKeyCommand = function (data, event) { if (event.shiftKey && event.keyCode == 49) { alert("Combination done !"); } }; }; <

附加按键事件:

我的视图模型:

Billing.BillingViewModel = function () {
    this.showSearcherCustomerKeyCommand = function (data, event) {
        if (event.shiftKey && event.keyCode == 49) {
            alert("Combination done !");
        }
    };
};
<section id="BillHeaderSecction" data-bind="event: { keypress: billingClient.showSearcherCustomerKeyCommand }, valueupdate: 'afterkeydown'">
HTML上的Section标记:

Billing.BillingViewModel = function () {
    this.showSearcherCustomerKeyCommand = function (data, event) {
        if (event.shiftKey && event.keyCode == 49) {
            alert("Combination done !");
        }
    };
};
<section id="BillHeaderSecction" data-bind="event: { keypress: billingClient.showSearcherCustomerKeyCommand }, valueupdate: 'afterkeydown'">


但当我根据自己的要求进行组合时,事件不会执行。如何将knockout中的事件附加到div、section等,而不是输入。谢谢

关键事件将在节或div有焦点时起作用。将tabindex=“0”指定给div元素,并聚焦该特定div,然后按任意键,键事件将起作用。
在此处输入代码

您不能这样做,因为
按键
相关,并且。
您可以尝试使用
鼠标悬停和鼠标悬停
。如果需要的话,试着这样做。干杯,但当最终用户使用ctrl+1组合键时,我需要它。。。不管怎样,我的应用程序可以做一些事情,比如显示弹出窗口、隐藏模式、设置焦点等等。。。击倒是不可能的???据我所知,我们不能基于部分或div的键附加事件。