首页 > 解决方案 > 通过脚本 jquery 将事件类型 (keyup) 更改为 (keyup.enter)

问题描述

我需要创建一个 jQuery 脚本来忽略 keyup 或 keypress 事件侦听器函数的执行,并在我按下键盘上的 Enter 键时执行它。

我正在使用 jquery 的一个组件,所以我无法更改输入的 html 代码。

HTML

 <input type="text" id="search" class="search" (keyup)="searchDataTable($event)">

查询:

$(document).on("keypress", "input", function(e) {
    var keyCode = e.keyCode || e.which;
    if (keyCode != 13) { 
        console.log('it is not enter keyCode ')
        //stop the execution of methode affected by event
    } 
});

我正在寻找禁用侦听器的 javascript 方法。 我想要:

A.仅当我按下“回车”时才执行函数。searchDataTable($event)

-或者-

B.通过其他脚本 jquery 将事件类型 (keyup) 更改为 (keyup.enter)。

标签: javascriptjqueryangulardatatables

解决方案


推荐阅读