多次运行 Kendo UI/jQuery 单击事件 [英] Kendo UI/jQuery click event running multiple times

查看:22
本文介绍了多次运行 Kendo UI/jQuery 单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Telerik 的名为 Kendo UI 的 jQuery 软件来创建一个模态弹出窗口.我在使用 Kendo 模式弹出框时遇到了一个相当奇怪的问题,其中包含一个 "Confirm"/"Cancel" 确认.我第一次打开确认窗口&单击任一按钮(确认或取消),窗口将正常工作.我第二次打开这个弹出窗口 &单击一个按钮,我的 Kendo 的 click 事件会触发两次.第三次打开窗口时,点击事件触发了 3 次,依此类推.我不知道为什么.它应该只触发一次.

I'm using Telerik's jQuery software called Kendo UI, to create a modal popup window. I'm having a rather odd problem with a Kendo modal popup box, which contains a "Confirm"/"Cancel" confirmation. 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. The third time I open the window, the click event fires 3 times, etc. I can't figure out why. It should only be firing once.

这是我的 JS 代码.两次触发的点击功能在 Confirm &取消部分,从读取 .click(function () { :

Here's my JS code. The click function that's firing twice is in both the Confirm & Cancel sections, beginning on the line that reads .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();

知道我做错了什么吗?

谢谢

推荐答案

听起来您应该只初始化对话框一次(创建它并添加处理程序).然后每次你需要对话框显示你只调用你的

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.

这篇关于多次运行 Kendo UI/jQuery 单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆