$(document).ready(function() {
$('a.register-window').click(function () {
var popupBox = $(this).attr('href');
$(popupBox).fadeIn(400);
var popupMarginTop = ($(popupBox).height() + 24)/2;
var popupMarginLeft = ($(popupBox).width() + 24)/2;
$(popupBox).css({
'margin-top' : -popupMarginTop,
'margin-left' : -popupMarginLeft
});
$('body').append('<div id="screen-shadow"></div>');
$('#screen-shadow').fadeIn(300);
return false;
});
$('button.close, #screen-shadow').live('click', function() {
$('#screen-shadow , .register-popup').fadeOut(300, function() {
$('#screen-shadow').remove();
});
return false;
});
});
上面是Jquery代码,我用它来显示论坛的弹出登录表单。我设法用这个代码显示弹出窗口就好了,但通过单击按钮或单击(屏幕阴影)基本上是一个掩码来关闭它不起作用。我将非常感谢对此的一些帮助:)。
答案 0 :(得分:1)
我建议您使用on()
代替live()
。您可以尝试以下
$('body').on('click', 'button.close, #screen-shadow', function() {
$('#screen-shadow, .register-popup').fadeOut(300, function() {
$('#screen-shadow').remove();
});
return false;
});
答案 1 :(得分:0)
检查括号,Prentiss等的打开和关闭。似乎您忘记了代码中的某些内容..