Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery ui Jquery UI Accordion-取消更改_Jquery Ui_Accordion_Jquery_Jquery Ui Accordion - Fatal编程技术网

Jquery ui Jquery UI Accordion-取消更改

Jquery ui Jquery UI Accordion-取消更改,jquery-ui,accordion,jquery,jquery-ui-accordion,Jquery Ui,Accordion,Jquery,Jquery Ui Accordion,我已经和这个摔跤一段时间了 我想在有人换手风琴之前先确认一下 我试过: $(document).ready(function() { var edited = false; $(".accordion-me").accordion({ autoHeight: false, navigation: true, changestart: function(event, ui) { if (edited) {

我已经和这个摔跤一段时间了

我想在有人换手风琴之前先确认一下

我试过:

$(document).ready(function() {

    var edited = false;

    $(".accordion-me").accordion({
        autoHeight: false,
        navigation: true,
        changestart: function(event, ui) {
            if (edited) {
                if (!confirm("You have unsaved changes. Do you want to navigate away?") {
                    event.preventDefault();
                    event.stopPropagation();
                    event.stopImmediatePropagation();
                    return false;
                }
            }
        }
    });
});
一点也不高兴!我也试过类似的方法

   $(".accordion-me h3").each(function() {

                    $(this).unbind("click");

                    $(this).click(function(e) {

                        if (confirm("You have unsaved changes! Do you want to navigate away?")) {
                            $(this).unbind("click");
                            $(".accordion-me").accordion({
                                autoHeight: false,
                                navigation: true,
                                changestart: function(event, ui) {
                                    if (edited) {
                                        if (!confirm("You have unsaved changes. Do you want to navigate away?") {
                                            event.preventDefault();
                                            event.stopPropagation();
                                            event.stopImmediatePropagation();
                                            return false;
                                        }
                                    }
                                }
                            });                            
                            $(this).click();
                        }
                    });
                });
但同样没有快乐

任何帮助都将不胜感激


干杯

您必须将其绑定到锚定标记上的单击事件。例如,如果标题链接为:

<a href="#" class="accordionHeaderLink">header 1</a>

创建手风琴时使用空事件,这将允许您使用jQuery.click函数管理手风琴的click事件。 然后,您可以处理确认框,并仅在确认后才允许执行手风琴单击事件

$(document).ready(function()
{
    var edited = false,
        accordion_me = $('.accordion-me');

    // activate the accordion, but with an empty event
    accordion_me.accordion({
        autoHeight: false,
        navigation: true,
        event: ''
    });

    // here's the new accordion event
    $('.accordion-me h3').click(function()
    {
        // find the index of the event being called
        var i = $('.accordion-me h3').index(this);

        // if we have unsaved changes and do not confirm, stop accordion execution      
        if (edited && !confirm('You have unsaved changes. Do you want to navigate away?'))
        {
            return false;
        }

        // continue with the accordion execution. Activate the requested event index.
        accordion_me.accordion('activate', i);

        return false;
    });
});
如果你的手风琴是可折叠的(就像我的一样),你的手风琴仍能像以前一样工作。 另外,如果您只有1个accordion,我建议使用id来调用它,而不是.accordion me类,这将节省一些开销。
如果您仍然需要使用类来调用它,请在它前面放置一个html标记,即div.accordion-me。

我在使用ui对话框确认时遇到类似问题。我仍然不能让它工作,甚至绑定到点击事件。手风琴随着ui对话框的出现而改变。这就是我要找的!谢谢:)
$(document).ready(function()
{
    var edited = false,
        accordion_me = $('.accordion-me');

    // activate the accordion, but with an empty event
    accordion_me.accordion({
        autoHeight: false,
        navigation: true,
        event: ''
    });

    // here's the new accordion event
    $('.accordion-me h3').click(function()
    {
        // find the index of the event being called
        var i = $('.accordion-me h3').index(this);

        // if we have unsaved changes and do not confirm, stop accordion execution      
        if (edited && !confirm('You have unsaved changes. Do you want to navigate away?'))
        {
            return false;
        }

        // continue with the accordion execution. Activate the requested event index.
        accordion_me.accordion('activate', i);

        return false;
    });
});