2012-04-20 48 views
1

我写这段代码来显示当我去#story-comments-text调用$ .get请求的另一个div(#comments-popup)为它的html代码。

这部分工作正常。

我在调用$ .post请求时遇到问题。

#comments-popup通过调用$ .post()的提交按钮进行更新。该请求很好,但在div更新后,当我将鼠标移到它上面时,它显示了很多#comments - 弹出第一个的底部。哪里有问题?我该如何解决它?我仍然是ajax的noob。对不起我英文不好的人!

$("#story-comments-text").mouseenter(function() 
{ 
    var popupdiv="<div id='comments-popup'></div>"; 
    var href = jQuery(location).attr('href'); 
    var newHref=href+"&comment=1"; 
    if($("comments-popup").is(":visible")) 
    { 
     $("comments-popup").remove(); 
    } 
    $.get 
    ( newHref, 
     function(data) 
     { 
      $("#story-comments-text").append(popupdiv); 
      $("#comments-popup").css("display", "none"); 
      $("#comments-popup").html(data); 
      $("#comments-popup").fadeIn(); 
      $("#story-comment-submit").click(function(e) 
      { 
       e.preventDefault(); 
       var href = jQuery(location).attr('href'); 
       var newHref=href+"&comment=1&addcomment=1"; 
       var comment=$("#story-comment-form #story-comment-form-text").val(); 
       $.post 
       (
        newHref, 
        { 
         "comment":comment 
        }, 
        function(data) 
        { 
         if(data) 
         { 
          $("#comments-popup").remove(); 

          $("#comments-popup").css("display", "none"); 
          $("#comments-popup").html(data); 
          $("#comments-popup").fadeIn(); 
         } 

        } 
       ); 
      }); 
     } 
    ); 

回答

0

变化

if($("comments-popup").is(":visible")) 
{ 
    $("comments-popup").remove(); 
} 

if($("#comments-popup").is(":visible")) 
    { 
     $("#comments-popup").remove(); 
    } 

只是猜测,有可能是错误的。

+0

仍然是同样的问题... – 2012-04-20 13:10:09