其他答案不相关,我没有注意到它是 FancyBox。
一个类似的问题张贴在这里,这里和这里。正如@JFK 在第一个链接中所说,您可以使用图像属性的 data-, 前缀来保存标题信息。并使用 jquery 脚本访问它。
<!doctype html>
<html>
<head>
. . .
<title>your demo</title>
</head>
<body>
<div id="gallery" class="residences">
<div class="bigImages">
<ul>
<li>
<div class="gallery-image">
<img class="caption" src="images/lifestyle-gallery/img2.jpg" title="Caption 1" data-caption="Caption will go here">
</div> <!-- /gallery-image -->
</li>
脚本将是:
$(document).ready(function() {
$(".fancybox").fancybox({
helpers : {
title: { type: 'inside'}
},
// use the following if you want to do the caption before the image
// beforeShow : function(){
afterLoad: function(){
this.title = this.title + ' ' + $(this.element).data("caption");
//you can also do the following to use the alt instead of the caption
//this.title = this.title + ' ' + $(this.element).find('img').attr('alt');
}
}); // fancybox
}); // ready