对话框按键和DOM [英] Dialog keypress and DOM
问题描述
我试图使用jQuery的按键来触发一个按钮,点击使用jQuery对话框功能创建的模态对话框。问题是,使用以下代码,它第一次工作(按Enter按下保存按钮),但是当我关闭模态对话框并重新打开它时,我会收到不规则的行为。我正在考虑一些 $(this)的变体(button:contains('Save'))
会工作,但这不起作用。 >
I'm trying to use jQuery's keypress to trigger a button click on a modal dialog created using the jQuery dialog function. The problem is, with the following code, it works the first time around (pressing enter presses the Save button) but I get erratic behavior when I close the modal dialog and reopen it. I'm thinking some variant of $(this).("button:contains('Save')")
would work, but that doesn't work.
$('#dialog').keypress(function(e) {
if (e.which == 13) {
$("button:contains('Save')").click();
}
});
使用$(#对话框)对话框打开对话框('open') ,而不是autoOpen:true。
任务的最佳做法是什么?
FYI the dialog is opened using a $("#dialog").dialog('open'), not an autoOpen:true. What would be the best practice for the task?
谢谢!
推荐答案
keypress是为字母。 keydown是为了一切。我会尝试使用keydown。
keypress is for letters. keydown is for everything. I would try using keydown.
您的代码很可能无法执行。输入将触发默认动作,这就是为什么它第一次工作。
Your code most likely does not execute. Enter will trigger the default action so that's why it works the first time.
更多信息:
< a href =http://www.bloggingdeveloper.com/post/KeyPress-KeyDown-KeyUp-The-Difference-Between-Javascript-Key-Events.aspx =nofollow noreferrer> http://www.bloggingdeveloper .com / post / KeyPress-KeyDown-KeyUp-Javascript-Key-Events.aspx之间的区别
这篇关于对话框按键和DOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!