[英]JQuery UI - Add dblclick Event to Modal dialogs
I'm using JQuery UI to generate modal dialogs. 我正在使用JQuery UI生成模态对话框。 I generate them after clicking a div.
我点击一个div后生成它们。 The problem is adding a dblclick event on the title bar span after generating it.
问题是在生成标题栏跨度后添加dblclick事件。 The ID got set automatically and I'm trying to add the event by this code after generating them:
ID已自动设置,我正在尝试在生成它们之后通过此代码添加事件:
$("div").find('span#ui-id-1.ui-dialog-title').on('dblclick', function () {
alert("test");
});
Unfortunately it doesn't work, but it works when I execute it using the debug console whyever. 不幸的是它不起作用,但是当我使用调试控制台执行它时,它可以工作。
change to this: 改为:
$("body").on('dblclick', 'span#ui-id-1.ui-dialog-title', function () {
because modals are dynamically created so, event has to be delegated to the static parent or to the $(document)/$('body')
. 因为模态是动态创建的,所以必须将事件委托给静态父级或
$(document)/$('body')
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.