gpt4 book ai didi

javascript - 我无法捕获 select2 中的回车键

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:16:25 24 4
gpt4 key购买 nike

我正在使用 select2,我需要捕获回车键,但我做不到。

我用过:

$(document).on('keydown', '.select2-input', function (ev) {

if (ev.which == 13) {
alert('press enter')
}

if (ev.which == 9) {
ev.preventDefault();
ev.stopImmediatePropagation();
alert('press tab')
}
});

除了回车键,我可以捕捉到所有的键。

有人可以帮助我吗?

最佳答案

试试这个,本质上是一样的:

$(document).on('keyup keypress keydown', ".select2-input", function (e) {
if (e.which == 13) {
console.log("Pressed enter!");
}
});

关于javascript - 我无法捕获 select2 中的回车键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29573265/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com