开发者

jQuery Fancybox get id value of a

what I'm trying to do is get the ID value of the referring a. The code for my a looks like:

<a class="photoBig" id="<?php echo $photo['id'] ?>" href="<?php echo $f->buildPhotoURL($photo, 'large') ?>" title="<?php echo $photo['title'] ?>">

I'm using phpFlickr to assign the ID's plus some various other things, which works fine.

So the code to open a Fancybox I use is:

$("a.photoBig").attr('rel', 'gallery').fancybox({
            'titleShow'     : true,
            'overlayOpacity' : 0.9,
            'overlayColor' : '#000',
            'autoScale' : false,
            'scrolling' : true,
            'titlePosition' : 'inside',
            'showNavArrows' : true,
            'cyclic' : true,
            'showCloseButton' : false,
            'titleFormat' : formatTitle
        });

then the function fomatTitle, which is:

function formatTitle(title, id, currentArray, currentIndex, currentOpts) {
    return '<div id="photoBig-title"><span><a href="javascript:;" onclick="$.fancybox.close();"><img src="images/site/closelabel.gif"></a></span>' + (title && title.length开发者_如何学C ? '<strong>' + title + '</strong>' : '' ) + $(this).id + '<a href="http://www.flickr.com/photos/rustybones/' + this.id + '" title="view original on flickr">view full size</a></div>';
}

Everything works in this function except for this.id. Obviously I'm doing this wrong, so any help would be tops! Thank you.


Change

$(this).id
to
this.id
or
$(this).attr('id')

and see if that works.

EDIT: Okay, I've tested this and it works:

Use currentArray[currentIndex].id to get the id.

Alternatively, if all you wanted was the id so you could use it to point to your image, you could just use $(this).attr('href') in it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜