我有两个脚本
$(".MakeBid").on('click', function(e) {
e.preventDefault();
if ($('#pop_up').length) {$('#pop_up').html("").height('auto').width('auto').offset({left:0,top:0});}
var strSrc = 'index.asp?id=' + $(this).attr('id');
$.get(strSrc, function(data) {
if ($('#pop_up').length) {
$('<iframe src="' + strSrc + '"/>').appendTo('#pop_up');
$('#pop_up').show(function() {
$('#pop_up').height(150).width(800);
$('#pop_up').offset({top:e.pageY,left:e.pageX});
$('#pop_up').on( "mouseleave", function() {
if ($('#pop_up').length) {
$('#pop_up').html("").height('auto').width('auto').offset({left:0,top:0});
$('#pop_up').hide();
}
$('#pop_up').unbind();
});
$('.authorize-close').click(function(e){
e.preventDefault();
if ($('#pop_up').length) {
$('#pop_up').html("");
$('#pop_up').hide();
}
});
});
}
});
$(".MakeBid").unbind('click');
});
并且
$(".Login").on('click', function(e) {
e.preventDefault();
if ($('#pop_up').length) {$('#pop_up').html("").height('auto').width('auto').offset({left:0,top:0});} //restore div position and offset
var strSrc = 'index.asp?id=' + $(this).attr('id');
$.get(strSrc, function(data) {
if ($('#pop_up').length) {
$('<iframe src="' + strSrc + '"/>').appendTo('#pop_up');
$('#pop_up').show(function() {
$('#pop_up').height(150).width(800); //set div size
$('#pop_up').offset({top:e.pageY,left:e.pageX}); // set div offset
$('.authorize-close').click(function(e){ //on close button press
e.preventDefault();
if ($('#pop_up').length) {
$('#pop_up').html(""); //empty div
$('#pop_up').hide(); // hide div
}
});
});
}
});
$(".Login").unbind('click');
});
所以当我点击.MakeBid $('#pop_up').on( "mouseleave",
时激活,关闭#pop_up并点击.Login $('#pop_up').on( "mouseleave",
仍在工作。
如何解开这个?
答案 0 :(得分:1)
你必须修改$('#pop_up')。unbind(); to $('#pop_up')。off(“mouseleave”);如下面的代码
$('#pop_up').on( "mouseleave", function() {
if ($('#pop_up').length) {
$('#pop_up').html("").height('auto').width('auto').offset({left:0,top:0});
$('#pop_up').hide();
}
$('#pop_up').off("mouseleave");
});