首先,讓你的comments_template()
回報完整的字符串。
然後,嘗試像這樣構建您的代碼。你想.hide()
對.ready()
的評論,然後.show()
他們當你點擊.comment-button
按鈕。
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<button class="comment-button">Show Comments</button>
<p class="comments"><?php echo comments_template(); ?></p>
<script>
$("document").ready(function() {
$(".comments").hide();
$(".comment-button").click(function() {
$(".comments").show("slow");
});
});
</script>
</body>
不要在jQuery中使用帶有$()
的直接元素;使用班級或ID。
另外,如果你想有一個輝煌框架使用可以摺疊與微妙的動畫元素,嘗試Bootstrap for Twitter然後做這樣的事情:
<div class="comment-1 collapse">
<?php echo comments_template(); ?>
</div>
<button data-target=".comment-1" data-toggle="collapse">Show Comment</button>
沒有所需的JavaScript,因爲它已經在引導圖書館。
請告訴我們你是如何插入它。 – Daedalus 2013-02-14 00:55:11
你要在哪裏插入它?我沒有看到任何東西 – pwolaq 2013-02-14 00:55:16
你還沒有關閉你的頭標籤。還需要顯示HTML,然後在$(「document」)上顯示'.hide()'。ready()' – Amelia 2013-02-14 00:57:07