Javascript“确认"框显示多次. jQuery的 [英] Javascript "confirm" box displaying more than once. jQuery

查看:83
本文介绍了Javascript“确认"框显示多次. jQuery的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Adiv调用,当单击div时会运行它.这将显示一个动态下拉菜单.下面是ajax调用.

I have an Ajax call that is run when a div is clicked. This displays a dynamic drop down menu. Below is the ajax call.

下拉菜单包含其他项目的列表,可以单击这些项目以启动编辑器".问题是,当我关闭编辑器时,我要求用户确认他们要离开页面,基于答案,div将关闭或保持打开状态以供进一步编辑.下面是启动编辑器的代码:

The drop down menu contains a list of other items that can be clicked to launch an "editor". The issue is that when I close the editor I request the user confirm they want to navigate away from the page, based on the answer the div will either close or remain open for further editing. Below is the code that launches the editor:

jQuery(function($){


    var launchEditor = "#launch-editor-<?php echo $this->section_num; ?>";
    var contentEditor = jQuery("#<?php echo $this->section_num; ?>-editor");
    var closeEditor = "#<?php echo $this->section_num; ?>-editor-close";
    var closeMessage = "Your changes will not be saved, are you sure you want to close without saving?";

    jQuery(document).on("click", launchEditor, function(){
        contentEditor.unbind();
        contentEditor.show("fade", 1000);
        contentEditor.draggable();
    });

    jQuery(document).on("click", closeEditor, function(){

        if(confirm(closeMessage)){
            contentEditor.fadeOut(1000);
            //contentEditor.die("click");   

        } else {

        }


    });
});

问题如下...如果我多次单击初始div并启动AJAX调用,则"jQuery(document).on("click",closeEditor ...)函数会冒泡用户决定关闭编辑器时会出现问题的DOM.有效地,确认"消息显示等于单击原始div的次数.希望这是有道理的...让我知道是否需要进一步的信息...干杯.

The issue is as follows... If I click on the initial div more than once which launches the AJAX call, the "jQuery(document).on("click", closeEditor...)" function bubbles up in the DOM which poses a problem when the user decides to close the editor. Effectively the "confirm" message displays equal to the amount of times the original div is clicked. hope this makes sense... let me know if further info is required... cheers.

推荐答案

以下内容似乎已解决..感谢SCRAGAR的建议:

Following seemed to fix it.. thanks SCRAGAR for your suggestion:

closeEditor.one().bind("click", function(){

    if(confirm(closeMessage)){
        contentEditor.fadeOut(1000);
    } else {
        //do something
    }

});

这篇关于Javascript“确认"框显示多次. jQuery的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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