我有一個鏈接,打開的fancybox盒如下:訪問「這個」的fancybox內選擇
<a class="fancybox" rel="gallery" href="<?php echo $image_src; ?>" data-id="<?php echo $post->ID; ?>">
鏈接已data
屬性填充瞭如上的id
。我想在Fancybox輔助函數中使數據屬性可用。我曾嘗試在下面的代碼中使用$(this.element).data('id')
:
helpers: {
title: {
type: 'over'
},
buttons: {
position: 'bottom',
tpl: '<div id="fancybox-buttons"><ul> \
<li class="button"><a class="test-btn" data-id="' + $(this.element).data('id') + '" href="#"></a></li> \
</ul></div>'
}
}
但是它不起作用。獲取數據屬性始終在幫助程序函數中返回undefined
。我如何得到這個工作。
只要小心你的解決方案。缺點是'my_global_var'對於第一個元素仍然是'undefined'。然後它會將第一個元素的'$(this.element).data('id')'的值應用到第二個元素等,等等。 – JFK
@JFK這就是我最初想到的。但是,這也適用於第一個元素,沒有任何問題。 – John
很難相信沒有看到它;) – JFK