我正在一个带有多个锚点的页面中工作。单击时,每个锚点都有单独的内容要弹出。我的功能可以正常工作,但是当我单击不同的锚点时,它会从第一个锚点重复相同的内容。我需要让每个锚点在弹出窗口中显示相应的内容。下面是我的代码。先感谢您。
<script>
$(document).ready(function() {
$('a.bio, a.bio2').click(function() {
//Getting the variable's value from a link
var loginBox = $(this).attr('href');
//Fade in the Popup
$(loginBox).fadeIn(300);
//Set the center alignment padding + border see css style
var popMargTop = ($(loginBox).height() + 24) / 2;
var popMargLeft = ($(loginBox).width() + 24) / 2;
$(loginBox).css({
'margin-top' : -popMargTop,
'margin-left' : -popMargLeft
});
// Add the mask to body
$('body').append('<div id="mask"></div>');
$('#mask').fadeIn(300);
return false;
});
// When clicking on the button close or the mask layer the popup closed
$('a.close, #mask').live('click', function() {
$('#mask , .login-popup').fadeOut(300 , function() {
$('#mask').remove();
});
return false;
});
});
</script>
的HTML
<a class="bio" href="#login-box">READ BIO >></a>
<div class="login-popup" id="login-box">
<div id="popupimage">
<h2>This is image 1</h2>
</div></div>
<a class="bio2" href="#login-box">READ BIO >></a></div>
<div class="login-popup" id="login-box">
<div id="popupimage">
<h2>This is image 2</h2>
</div></div>
CSS
.login-popup {
background: none repeat scroll 0 0 #585858;
display: none;
float: left;
font-size: 1.2em;
height: 350px;
left: 50%;
padding: 20px;
position: fixed;
top: 50%;
width: 500px;
z-index: 999999999;
color:#FFF;
}