Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.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
如何将当前索引传递给fancybox iframe_Iframe_Fancybox - Fatal编程技术网

如何将当前索引传递给fancybox iframe

如何将当前索引传递给fancybox iframe,iframe,fancybox,Iframe,Fancybox,我有一组我称之为fancybox的链接,并启用了箭头,以便用户可以单击next和prev。每个链接都用iframe类和href='/editdata.aspx'修饰。我想删除箭头并传入当前索引,这样editdata.aspx save按钮就可以说“保存并下一步”,直到到达最后一个链接,最后一个链接会说“保存并关闭” 从editdata.aspx我使用 var numLinks = $(".link-items", parent.document.body).children("a.iframe"

我有一组我称之为fancybox的链接,并启用了箭头,以便用户可以单击next和prev。每个链接都用iframe类和href='/editdata.aspx'修饰。我想删除箭头并传入当前索引,这样editdata.aspx save按钮就可以说“保存并下一步”,直到到达最后一个链接,最后一个链接会说“保存并关闭”

从editdata.aspx我使用

var numLinks = $(".link-items", parent.document.body).children("a.iframe").size();
这给了我链接的总数。我只需要知道显示给用户的当前链接,以便更新保存按钮文本

以下是我在editdata.aspx中的代码示例:

// change the save button to save and next if fancybox is loading multiple links
        if (parent.$.fancybox) {
            var links = $(".links", parent.document.body);
            if (links && links.length > 0) {
                var numlinks  = $(links).children("a.popup").size();
                var index = getParameterByName('index');
                if (index == numlinks ) {
                    // this element is the last item to display so change the "save and next" to "save and close"
                    $("#btnSave").val("Save & Close");
                    $("#btnSave").click(function () {
                        parent.$.fancybox.close();
                    });
                }
                else {
                    $("#btnSave").val("Save & Next");
                    $("#btnSave").click(function () {
                        parent.$.fancybox.next();
                    });
                }
            }                
        }

function getParameterByName(name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results == null)
            return "";
        else
            return decodeURIComponent(results[1].replace(/\+/g, " "));
    }
我怎样才能做到这一点呢?

这对v2来说很容易-

jQuery(".fancybox").fancybox({
    beforeLoad : function() {
        this.href = this.href + '?index=' + this.index;
    }
});

这似乎对我不起作用。this.index的值始终是相同的数字。所有的href都有相同的索引值。我更新了我的问题,将我正在iframe页面中使用的jquery包括在内。这对我来说绝对有效。顺便说一句,您可以在iframe中获得索引,比如-parent.$.fancybox.current.index(或者如果您正在预加载iframe,则使用parent.$.fancybox.coming.index)是的,您是正确的。我的代码中还有其他东西导致了问题。当我创建一个简单的测试页面时,索引正在正确加载。