[英]How can I stop jquery ui dialog executes on pressing Enter
I have an input field that I have bound an event on keypressed, but when I press Enter (to execute the event for the input) two dialogs from jQuery UI pops open and ruin my variables. 我有一个输入字段,我已在按键上绑定了一个事件,但是当我按Enter键(为输入执行事件)时,jQuery UI的两个对话框会弹出并破坏我的变量。 How can I stop the events bound to the enter key for dialogs?
如何停止与对话框的Enter键绑定的事件?
$("#itemSample").on('keypress', function (e) {
if (e.keyCode == 13 && $("#itemSample").val().trim().length > 0) {
//do something
}
});
On the parameter 'e' (Event) you have the necessary functions: 在参数“ e”(事件)上,您具有必要的功能:
$("#itemSample").on('keypress', function (e) {
if (e.keyCode == 13 && $("#itemSample").val().trim().length > 0) {
// You probably need just one of the following two lines:
e.preventDefault();
e.stopPropagation();
}
});
For more info: http://css-tricks.com/return-false-and-prevent-default/ 有关更多信息: http : //css-tricks.com/return-false-and-prevent-default/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.