2010-06-06 184 views
0

我正在在我的網頁下面的調用:從控制器返回部分視圖時重新加載jQuery?

<div id="comments"> 
    <fieldset> 
      <h4> 
       Post your comment</h4> 
      <% using (this.Ajax.BeginForm("CreateStoryComment", "Story", new { id = story.StoryId }, new AjaxOptions { UpdateTargetId = "comments", OnSuccess = "OnStoryCommentAdded" })) 
       { %> 
      <%= this.Html.TextArea("Body", string.Empty)%> 
      <input type="submit" value="Add Comment" /> 
      <% } %> 
    </fieldset> 
</div> 

還有其他的代碼,但是這是它的要點。控制器返回一個局部視圖,在評論div中「刷新」每一個。

我的問題是,沒有應用以下的jQuery:

$(".comment .delete").click(function() { 
    if (confirm("Are you sure you want to delete this record?") == true) { 
     $.post(this.href); 
     $(this).parents(".comment").fadeOut("normal"); 
    } 
    return false; 
}); 

我假設它沒有被連接,因爲jQuery的負載inital頁面加載後。如果我的假設是正確的,我如何獲得這個jQuery來「刷新」。

希望這是有道理的! :)

回答

2

使用.live關鍵字將代碼關聯到在文檔內創建的元素。

+0

完美的工作!謝謝! – mattruma 2010-06-07 01:02:57

相關問題