【问题标题】:Jquery Jqui Modal Window: opening same modal multiple timesJquery Jqui模态窗口:多次打开同一个模态
【发布时间】:2014-04-23 20:55:15
【问题描述】:

我正在开发一个 javascript 函数,它打开一个 jquery 模态窗口并进行 ajax 调用来填充模态。我已经包含了“左”和“右”的 div id - 单击一个会更改模式窗口的内容(滚动照片幻灯片)。

一切都很好,除了一件事:如果我打开模式然后关闭它,第二次打开它会导致这些“左/右”按钮将每次点击计为两次(点击一次“右”,但移动两个图像结束)。如果我关闭窗口并再次打开它,计数会再次增加 1(1 次单击更改 3)。

解决此问题的唯一解决方法是在模式窗口关闭时重新加载页面 - 但有人知道更好的解决方案吗?基本上,我想“重置”模式窗口,但不想破坏它——我希望能够多次打开/关闭模式并让这些右/左按钮工作。

我用来创建这些按钮的部分功能如下 - 感谢您提供任何建议/想法。

    function getNextImage(direction) {
        if(direction == 1) {
            if(imageNumber == 1) {
                    imageNumber = lastImage;
                } else {
                    --imageNumber;
                }
            }
        if(direction == 2) {
            if(imageNumber == lastImage) {
                    imageNumber = 1;
                } else {
                    ++imageNumber;
                }
            }
        if(direction == 0) {
            imageNumber = 1;
        }

        $.ajax({
            type: "GET",
            url: "phpIncludes/next_fetch.php",
            cache: false,
            data: {img : imageNumber, cap : imageNumber, width : dWidth, height : dHeight, a : album},
            success: function(htmlpic) {
                $("#left"+album).html(htmlpic);
            }
        });
    }

    $("#moveLeft"+album).click(function() {
        getNextImage(1);
        console.log("Image Number is: " + imageNumber);
    });

    $("#moveRight"+album).click(function() {
        getNextImage(2)
        console.log("Image Number is: " + imageNumber);
    });

【问题讨论】:

    标签: javascript jquery ajax increment jqui


    【解决方案1】:

    在这部分::

    $.ajax({ 类型:“获取”, url: "phpIncludes/next_fetch.php", 缓存:假, 数据:{img:imageNumber,cap:imageNumber,width:dWidth,height:dHeight,a:专辑}, 成功:函数(htmlpic){ $("#left"+专辑).html(htmlpic); } });

    在您将 htmlpic 添加到 #left 之前,proib 首先将此内容清空 #left 并验证它是否完成!

    【讨论】:

    • 感谢您的好主意!不幸的是,我试过了,但没有用。如果模式关闭然后重新打开,左/右按钮仍会获得“+1”增量。
    猜你喜欢
    • 2016-12-11
    • 2012-03-18
    • 2016-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多