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

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

问题描述

我使用的是Telerik的jQuery软件,称为Kendo UI,以创建模式弹出窗口.我在Kendo模态弹出框上遇到一个比较奇怪的问题,该弹出框包含确认"/取消"确认.我第一次打开确认窗口单击任一按钮(确认"或取消"),窗口将正常工作.我第二次打开此弹出窗口&单击一个按钮,我的剑道的"click"事件会触发两次.第三次打开窗口时,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();

代码行.看起来每次您打开对话框时,都会添加一个新的单击处理程序,并且以前的处理程序和新的处理程序都将在click事件上被调用.

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 click事件多次运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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