javascript
  • jquery
  • ruby
  • ruby-on-rails-3
  • 2013-02-28 39 views 0 likes 
    0

    我有問題,當jquery追加字符串,而不是標籤。 這裏是我的代碼:附加jquery

    $('.nested_comments_'+<%= @comment.parent.id %>).append("<div class='<%= 'nested_comments nested_comments_'+ @comment.id.to_s%>'></div>") 
    

    ,這導致

    "<div class='nested_comments nested_comments_584'></div>" 
    

    而不是HTML標籤。我究竟做錯了什麼?

    +0

    你缺少最後')'; – andlrc 2013-02-28 12:52:43

    +0

    我擁有它,只是在複製時錯過了 – 2013-02-28 12:58:05

    回答

    0

    你確定你是不是簡單地丟掉了最後parentes:

    $('.nested_comments_'+<%= @comment.parent.id %>).append("<div class='<%= 'nested_comments nested_comments_'+ @comment.id.to_s%>'></div>"); 
    

    您可以使用反向風格,採用appendTo

    $("<div class='<%= 'nested_comments nested_comments_'+ @comment.id.to_s%>'></div>").appendTo('.nested_comments_'+<%= @comment.parent.id %>); 
    
    +0

    這使我得到了同樣的結果 – 2013-02-28 12:58:54

    相關問題