this.id在fancybox里面 [英] this.id inside of fancybox
本文介绍了this.id在fancybox里面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正试图在标题中弹出一个fancybox,并将其中的Facebook LIKE按钮链接到基于哪个项目被点击的唯一页面。所有的图像都有一个唯一的数字,我只是试图用this.id来获得这个数字,但它没有返回任何东西。
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
'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 +'& amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; ght& amp; amp; amp; height = 35scrolling =noframeborder =0style =border:none;溢出:隐藏;宽度:350像素; height:35px;allowTransparency =true>< / iframe>< / span>';
return astring;
}
});
});
});
解决方案
在 .each
函数的另一个函数内访问这个
,所以这个
指的是其他东西,你可以将这个
复制到一个变量中,以便内部函数的安全访问:
$ b $每个(function(){
var element = this;
$(this).fancybox({
'titleFormat':function(){
var astring ='< span>'+ element.id +'< / span>';
return astring;
}
});
});
I'm attempting to have a fancybox pop up with a facebook LIKE button in the title that links to the unique page based on which item is clicked. All of the images are id'ed with a unique number and I'm simply trying to get that number with this.id but it is not returning anything.
$(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;
}
});
});
});
解决方案
You're trying to access this
inside a different function to the .each
function, so this
refers to something else. You can copy this
into a variable though, for safe access inside the inner function:
$("a.fancybox").each(function() {
var element = this;
$(this).fancybox({
'titleFormat' : function() {
var astring = '<span>' + element.id + '</span>';
return astring;
}
});
});
这篇关于this.id在fancybox里面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文