我需要在fancybox中查看动态内容
我的代码看起来像
<a id="featureExpertPopup" href="#featureExpertPop">View Profile </a>
<a id="featureExpertPopup" href="#featureExpertPop">View Profile </a>
<a id="featureExpertPopup" href="#featureExpertPop">View Profile </a>
和精美的盒子内容
<div style="display: none;">
<div id="featureExpertPop" style="overflow:auto;">Dynamic Profile</div>
</div>
fancybox call
$("#featureExpertPopup").fancybox({
'titlePosition' : 'inside',
'transitionIn' : 'none',
'transitionOut' : 'none'
});
现在问题是仅为第一个锚链接打开弹出窗口,我想基于个人资料ID为每个具有不同内容(来自数据库)的链接打开弹出窗口。
答案 0 :(得分:3)
您不能对不同的元素使用相同的ID。使用class而不是ID
<a class="featureExpertPopup" href="#featureExpertPop">View Profile </a>
<a class="featureExpertPopup" href="#featureExpertPop">View Profile </a>
<a class="featureExpertPopup" href="#featureExpertPop">View Profile </a>
$(".featureExpertPopup").fancybox({
'titlePosition' : 'inside',
'transitionIn' : 'none',
'transitionOut' : 'none'
});
答案 1 :(得分:2)
您不应该为多个元素使用一个ID
,而是使用class
:
<a class="featureExpertPopup" id='one' href="#featureExpertPop">View Profile </a>
<a class="featureExpertPopup" id='two' href="#featureExpertPop">View Profile </a>
<a class="featureExpertPopup" id='three 'href="#featureExpertPop">View Profile </a>\
$(".featureExpertPopup").fancybox({ ... })
$('a').click(function(e){
e.preventDefault();
var href = $(this).attr('href') + $(this).attr('id');
})