[英]this.id inside of fancybox
我正在嘗試彈出一個帶有標題的Facebook LIKE按鈕的花式框,該鏈接鏈接到基於單擊哪個項目的唯一頁面。 所有圖像都使用唯一的編號標識,而我只是想使用this.id來獲取該編號,但是它沒有返回任何內容。
$(document).ready(function() {
$("a.fancybox").each(function() {
$(this).fancybox({
'overlayShow' : true,
'autoDimensions': true,
'transitionIn' : 'elastic',
'transitionOut' : 'elastic',
'overlayColor' : '#000',
'overlayOpacity': 0.7,
'titlePosition' : 'inside',
'titleFormat' : function() {
var astring = '<span id="fb-title"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.myurl.com%2Fscript.php%3Fi%3D' + this.id + '&layout=standard&show_faces=false&width=350&action=like&font=lucida+grande&colorscheme=light&height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:350px; height:35px;" allowTransparency="true"></iframe></span>';
return astring;
}
});
});
});
您試圖在與.each
函數不同的函數中訪問this
函數,因此this
引用了其他內容。 您可以復制this
到一個變量但是,對於內部函數內部安全訪問:
$("a.fancybox").each(function() {
var element = this;
$(this).fancybox({
'titleFormat' : function() {
var astring = '<span>' + element.id + '</span>';
return astring;
}
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.