Fancybox插件:动态重写href选项

问题描述 投票:2回答:1

我有一些链接,如:

<a href='http://mysite.com/comment/123/edit' class='fancybox'>Edit comment</a>

和Fancybox插件:

$(".fancybox").fancybox();

当我点击链接时,我会看到http://mysite.com/comment/123/edit的一些页面,但我想看看http://mysite.com/comment/123/edit.js

我知道有href选项,但我怎么能重写它以在我的原始href结束时附加.js

javascript jquery fancybox
1个回答
5
投票

您可以在应用fancybox时更改href属性:

$(".fancybox").attr('href', function() { return $(this).attr('href') + '.js'; }).fancybox();

如果您不想更改属性(保持链接相同),但希望仅将其应用于fancybox,请使用您提到的href选项:

$(".fancybox").each(function () {
    $(this).fancybox({ href: $(this).attr('href') + '.js' });
});
© www.soinside.com 2019 - 2024. All rights reserved.