0

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

从我使用的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, " "));
    }

我怎样才能做到这一点?

4

1 回答 1

2

这对 v2 来说很容易 -

jQuery(".fancybox").fancybox({
    beforeLoad : function() {
        this.href = this.href + '?index=' + this.index;
    }
});
于 2012-06-13T15:32:03.000 回答