我有一些链接,如:
<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
。
您可以在应用fancybox时更改href
属性:
$(".fancybox").attr('href', function() { return $(this).attr('href') + '.js'; }).fancybox();
如果您不想更改属性(保持链接相同),但希望仅将其应用于fancybox,请使用您提到的href
选项:
$(".fancybox").each(function () {
$(this).fancybox({ href: $(this).attr('href') + '.js' });
});