0

嗨,我想向 facybox 标题函数注入额外的数据 deneme 是我想注入但没有成功的变量。

<a rel="example_group" title="Title comes here" data-deneme="<?php echo $galleryitem['idphotos']; ?>">sdasd</a>

$("a[rel=example_group]").fancybox({
            'transitionIn'      : 'none',
            'transitionOut'     : 'none',
            'titlePosition'     : 'over',
            'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
                var deneme=$(this).data('deneme');

                return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span><span stye="color:#FFF; cursor:pointer;" onclick="javascript:popUpWindow(&quot;<?php echo base_url();?>selectproductoptions/'+ deneme +'.html&quot;,10,10,660,550);">+ add to cart</span>';
            }
        });

deneme 总是未定义

我想出了如何做到这一点,而不是尝试单独获取 deneme 我在 urlofimage.jpg?DenemeComesHere 之类的 href 之后放置了 deneme

为了抓住定名,我像这样使用了 jquerys split 函数

var deneme = currentOpts.href.split('?');

谢谢...

4

1 回答 1

3

如果使用 fancybox v1.3.4

不幸的是,您不能使用$(this)(neither this) 来引用您调用 fancybox 的元素(假设这是一个设计错误),因此您必须引用整个 selector $("a[rel=example_group]")。要过滤当前元素,请使用currentIndex通过titleFormatAPI 函数传递的参数,例如:

'titleFormat': function(title, currentArray, currentIndex, currentOpts) {
                var deneme = $("a[rel=example_group]").eq(currentIndex).data('deneme');
                return '...etc'
}

... 或者 :

'titleFormat': function(title, currentArray, currentIndex, currentOpts) {
                var deneme = $("a[rel=example_group]:eq("+currentIndex+")").data('deneme');
                return '...etc'
}

...无论你喜欢什么。

如果使用 fancybox v2.x+

你可以参考$(this)使用$(this.element)

在您的情况下title,使用回调添加变量,beforeShow例如:

$("a[rel=example_group]").fancybox({
  // other API options
  beforeShow: function(){
    var deneme = $(this.element).data('deneme');
    this.title = 'some html' + this.title + 'other html' ... etc
  }
});
于 2012-12-17T06:52:04.360 回答