Jquery Chosen - 防止按下按键 [英] Jquery Chosen - Prevents capture of keypress

查看:130
本文介绍了Jquery Chosen - 防止按下按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div(id = div_search_fields),其中有几个jQuery Chosen下拉列表。连接到div我有一个按键捕获监听器,如果按下的键是Enter键,则通过单击隐藏的提交按钮提交所选的东西。

I have a div (id = div_search_fields) within which I have several jQuery Chosen dropdowns. Attached to the div I have a keypress capture listener which, if the key pressed is the Enter key, submits the selected stuff by clicking a hidden submit button.

$("#div_search_fields").keypress(function(e) {
    if (e.which == 13) {
        $("#hiddenSubmitButton").click();
    }
});

由于某种原因,如果我刚刚选择了一个选定的下拉列表中的选项,则永远不会调用此监听器。在div_search_fieldsDIV中我还有一个简单的文本输入框,如果我刚刚输入文本然后按Enter键,则会按预期触发监听器。

For some reason this listener is never called if I have just selected an option in one of the chosen dropdowns. Within the "div_search_fields" DIV I also have a simple text input box and if I have just entered text there and then press the Enter key, the listener is triggered as expected.

这必须与关注选定的下拉菜单有关,但我无法理解为什么?任何想法?

This must be something to do with focus on the Chosen dropdowns but I cannot fathom why? Any ideas?

推荐答案

我可以看到Jquery选择在keypress事件中使用e.preventDefault(),所以它不允许执行你的代码。应该有一些功能可以覆盖以实现你的目标,或者你可以获得e.preventDefault()。

As Far I can see Jquery chosen is using e.preventDefault() in keypress event so it is not allowing to execute your code. There should be some function which you can override to achieve your goal or you can get ride of e.preventDefault().

这篇关于Jquery Chosen - 防止按下按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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