开发者

Fancybox plugin: rewrite href option on the fly

开发者 https://www.devze.com 2023-03-31 00:19 出处:网络
I have got some links like: <a href=\'http://mysite.com/comment/123/edit\' class=\'fancybox\'>Edit comment</a>

I have got some links like:

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

And Fancybox plugin:

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

When I click on the link I'll see some page from http://mysit开发者_如何学JAVAe.com/comment/123/edit, but I want to see http://mysite.com/comment/123/edit.js.

I know there is href option, but how can I rewrite it to append .js at the end of my original href.


You can change the href attribute as you apply fancybox:

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

If you don't want to change the attribute (keep the link the same), but want it applied for fancybox only, use the href option you mentioned:

$(".fancybox").each(function () {
    $(this).fancybox({ href: $(this).attr('href') + '.js' });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号