jquery – 为花式框添加标题

嗨,你可能认为这是一个愚蠢的问题,但我正在尝试将标题添加到花哨的方框2.我对 javascript知之甚少,但在我的html底部有这个
<script type="text/javascript">
$(document).ready(function() {
    $(".fancybox").fancybox();
});
</script>

如果我尝试加入

$(".fancybox")
.attr('rel','gallery')
.fancybox({
    beforeLoad: function() {
        this.title = $(this.element).attr('caption');
}
});

我得到各种语法错误.

网站是:http://bit.ly/Wan5kr

解决方法

您当前的脚本是:
$(document).ready(function() {
  $(".fancybox").fancybox({
   helpers : { 
    title : { type : 'inside' }
   },// helpers
   afterLoad : function() {
    this.title = (this.title ? '' + this.title + '<br />' : '') + 'Image ' + (this.index + 1) + ' of ' + this.group.length;
   } // afterLoad
  }); // fancybox
 }); // ready

……但应该是(如果你不想要“第1页,共6页”):

$(document).ready(function() {
  $(".fancybox").fancybox({
   helpers : { 
    title : { type : 'inside' }
   } // helpers
  }); // fancybox
 }); // ready

另一方面,如果您更喜欢使用标题属性(因为当您悬停图像时标题显示为工具提示)更改标题,如标题所示

<a href="images/gallery/large/wing-back-chair.jpg" caption="Early 1900'....." rel="Sold" class="fancybox"><img width="304" height="350" alt="Winged back chair and ottoman" src="images/gallery/tn/wing-back-chair.jpg"></a>

并使用此脚本

$(document).ready(function() {
  $(".fancybox").fancybox({
   helpers : { 
    title : { type : 'inside' }
   },// helpers
   beforeLoad: function() {
    this.title = $(this.element).attr('caption');
   }
  }); // fancybox
 }); // ready

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...