2012-01-10 49 views
0

我將在我的Django項目中使用django-threadedcomments庫。
https://github.com/HonzaKral/django-threadedcommentsDjango插件中的Javascript問題

本教程給出了示例代碼,包括Javascript以回覆評論的線程評論風格。
我試過測試這個示例,並且該庫自身工作,但回覆評論的Javascript不起作用。
jquery加載或Django靜態文件加載沒有任何問題。

這是教程。 http://goo.gl/vyFw9

我在想:
1)腳本有什麼問題嗎?
2)如果沒有,關於爲什麼這不起作用的任何想法?

function show_reply_form(comment_id, url, person_name) { 
var comment_reply = $('#' + comment_id); 
var to_add = $(new Array(
'<div class="response"><p>Reply to ' + person_name + ':</p>', 
'<form method="POST" action="' + url + '">', 
'<ul>', '{{ form.as_ul|oneline }}', 
'<li><input type="submit" value="Submit Comment" /></li>', 
'</ul>', '</form>', '</div>').join('')); 
to_add.css("display", "none"); 
comment_reply.after(to_add); 
to_add.slideDown(function() { 
    comment_reply.replaceWith(new Array('<a id="', 
    comment_id,'" href="javascript:hide_reply_form(\'', 
    comment_id, '\',\'', url, '\',\'', person_name, 
    '\')">Stop Replying</a>').join('')); 
}); 
} 
function hide_reply_form(comment_id, url, person_name) { 
var comment_reply = $('#' + comment_id); 
comment_reply.next().slideUp(function(){ 
    comment_reply.next('.response').remove(); 
    comment_reply.replaceWith(new Array('<a id="', 
    comment_id,'" href="javascript:show_reply_form(\'', 
    comment_id, '\',\'', url, '\',\'', person_name, 
    '\')">Reply</a>').join('')); 
}); 
} 

<a id="c{{ comment.id }}" href="javascript:show_reply_form('c{{ comment.id }}','{% get_free_comment_url post comment %}','{{ comment.name }}')">Reply</a> 
+0

你可以複製你從瀏覽器的錯誤控制檯得到的任何Javascript錯誤嗎?在安裝了Firebug的Chrome或Firefox中按F12。 Ctrl-Shift-J會在Firefox中啓動Firebug。 – Hal 2012-01-10 08:13:39

+0

@harrison_m謝謝,我在錯誤控制檯得到了「show_reply_form未定義」。 – 2012-01-10 09:14:54

回答

0

我看到的第一件事是,你是不是追加to_add到文檔可言,即像$('#someExistingDiv').append(to_add);

創建to_add後,它必須被添加到DOM。我不認爲有任何JS錯誤。我很確定它只是沒有看到創建新的評論元素。

+0

謝謝!當我調用JS時,我在錯誤控制檯中得到了「show_reply_form未定義」。也許這不是JS錯誤。 – 2012-01-10 09:13:53

+0

它似乎沒有適當的範圍。試試這個: 'Reply' – Sandeep 2012-01-10 10:32:55

+0

謝謝@Sandeep我試過了:Reply但是得到了同樣的錯誤... – 2012-01-10 18:01:14