有没有办法从<img>
标签而不是<a>
标签中提取标题?
例如 HTML:
<a rel="fancybox" href="#">
<img src="ball.jpg" title="this is the caption i want to show in fancybox" alt="alt text here" />
</a>
<a rel="fancybox" href="#">
<img src="ball2.jpg" title="this is the caption2" alt="alt text here" />
</a>
<a rel="fancybox" href="#">
<img src="ball3.jpg" title="this is the caption 3" alt="alt text here" />
</a>
我已经尝试过了,但它不起作用:JQuery:
$("a[rel=fancybox]").fancybox({
'transitionIn': 'elastic',
'transitionOut': 'elastic',
'titlePosition': 'inside',
'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
title = $(this).find("img").attr("title");
return '<span>' + title + '</span>';
}
});