我的 jquery 对话框上有两个按钮“确定”和“取消”。我希望当用户在当前打开的 Jquery ui 对话框中按 Enter 时,它的行为就像单击“确定”一样。按钮定义如下:
$("#dialog-confirm").dialog({
autoOpen: true,
resizable: true,
modal: true,
width: 458,
Height: 184,
buttons: {
"Login": function () {
$(this).dialog("close");
$("#frmsetAccount").submit();
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
});
请提出解决方案
最佳答案
您可以使用 KeyPress 或 KeyUp 事件
$('#targetElement').on('keypress', function(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if(code == 13) { //Enter keycode
//close your dialog box. -make sure you get the dialog object first. then close it. or call some function which is in ok button.
}
});
键盘
$('#targetElement').keyup(function(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if(code == 13) { //Enter keycode
//Do something
}
});
关于jquery - 将 Enter 键绑定(bind)到 jquery ui 对话框按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14874415/