2012-04-19 82 views
0

作爲標題,我只寫了下面的代碼...是創建一個彈出div的好方法嗎?對不起,我的英語不好。添加彈出div,這是好方法嗎?

$("#story-comments-text").mouseenter(function() 
{ 
    var popupdiv="<div id='comments-popup'></div>"; 
    $(this).append(popupdiv); 
    $.post() 
    { 
     //post request for popupdiv 
    } 
    return false; 
}).mouseleave(function(){ 
    $("#comments-popup").remove(); 
}); 

回答

1
$("#story-comments-text").mouseenter(function(){ 
    var popupdiv = "<div id='comments-popup'></div>", 
     that = this; // that is reference of #story-comments-text 
    $.post('url', data, function(data) { // just a demo request, you will configure it 
     if(data) { 
      popupdiv.html(res); // make process as you want 
      that.append(popupdiv); 
     } 
    }, 'json'); 
}).mouseleave(function(){ 
    $("#comments-popup").remove(); 
}); 
0
$("#story-comments-text").mouseenter(function() { 
    var $this = this; 
    $.post('server.php', { name: "John", time: "2pm" }, function(data) { 
     $("<div id='comments-popup'></div>").html(data).appendTo($this); 
    }); 
}).mouseleave(function(){ 
    $("#comments-popup").remove(); 
}); 
0

用慢動作=)

$("#story-comments-text").mouseenter(function() { 
    var $this = this; 
    $.post('server.php', { name: "John", time: "2pm" }, function(data) { 
     $("<div id='comments-popup' style='display: none'></div>").html(data).appendTo($this); 
     $('#comments-popup').show("slow"); 
    }); 
}).mouseleave(function(){ 
    $('#comments-popup').hide("slow", function(){ 
     $("#comments-popup").remove(); 
    }); 
}); 
相關問題