我將在我的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>
你可以複製你從瀏覽器的錯誤控制檯得到的任何Javascript錯誤嗎?在安裝了Firebug的Chrome或Firefox中按F12。 Ctrl-Shift-J會在Firefox中啓動Firebug。 – Hal 2012-01-10 08:13:39
@harrison_m謝謝,我在錯誤控制檯得到了「show_reply_form未定義」。 – 2012-01-10 09:14:54