0

作为标题,我刚刚编写了以下代码...这是创建弹出 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();
});
4

3 回答 3

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();
});
于 2012-04-19T16:53:36.500 回答
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();
    });
});
于 2012-04-19T17:21:17.077 回答
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();
});
于 2012-04-19T16:57:46.930 回答