简体   繁体   English

多次运行的剑道 UI/jQuery 单击事件

[英]Kendo UI/jQuery click event running multiple times

I'm using Telerik's jQuery software called Kendo UI, to create a modal popup window.我正在使用 Telerik 的名为 Kendo UI 的 jQuery 软件来创建一个模态弹出窗口。 I'm having a rather odd problem with a Kendo modal popup box, which contains a "Confirm"/"Cancel" confirmation.我在使用 Kendo 模式弹出框时遇到了一个相当奇怪的问题,其中包含"Confirm"/"Cancel"确认。 The first time I open the confirmation window & click either button (Confirm or Cancel), the window works correctly.我第一次打开确认窗口并单击任一按钮(确认或取消)时,窗口工作正常。 The 2nd time I open this popup window & click a button, my Kendo's click event fires twice.我第二次打开这个弹出窗口并单击一个按钮时,我的 Kendo 的click事件会触发两次。 The third time I open the window, the click event fires 3 times, etc. I can't figure out why.第三次打开窗口时,点击事件触发了 3 次,依此类推。我不知道为什么。 It should only be firing once.它应该只发射一次。

Here's my JS code.这是我的 JS 代码。 The click function that's firing twice is in both the Confirm & Cancel sections, beginning on the line that reads .click(function () { :两次触发的点击函数都在 Confirm & Cancel 部分,从读取.click(function () {的行开始:

var kendoWindow = $("#delete-confirmation").kendoWindow({
    title: "Confirm",
    resizable: false,
    modal: true,
    center: true
});

kendoWindow.data("kendoWindow")
    .center().open();

kendoWindow
    .find(".delete-confirm")
    .click(function () {
        kendoWindow.data("kendoWindow").close();
        destroyItem();
    })
   .end();

kendoWindow
    .find(".delete-cancel")
    .click(function () {
        kendoWindow.data("kendoWindow").close();
    })
   .end();

Any idea what I'm doing wrong?知道我做错了什么吗?

Thanks谢谢

Sounds like you should initialize your dialog only once (create it and add your handlers).听起来你应该只初始化你的对话框一次(创建它并添加你的处理程序)。 Then every time you need the dialog to show you only call your然后每次你需要对话框显示你只调用你的

kendoWindow.data("kendoWindow").center().open();

line of code.代码行。 It looks like each time you go to open the dialog its adding a new click hanlder and the previous handlers and the new handler will all be called on the click event.看起来每次你打开对话框时,它都会添加一个新的点击处理程序,之前的处理程序和新的处理程序都将在点击事件上被调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM