需要一些關於我的崩潰/展開效果的指導。我的代碼如下。Jquery崩潰擴展效果
<div class="buttons">
<a class="km-collapse-forms expand-all" href="#">Expand All</a>
<a class="km-collapse-forms collapse-all hide" href="#">Collapse All</a>
</div>
$args = array(...);
$comments_query = new WP_Comment_Query;
$comments = $comments_query->query($args);
foreach ($comments as $comment) {
<a class="respond-to-messages expand-form" href="#<?php echo $comment->comment_ID; ?>">Respond to message</a>
<a class="respond-to-messages collapse-form hide" href="#<?php echo $comment->comment_ID; ?>">Hide form</a>
<div id="comment-<?php echo $comment->comment_ID; ?>" class="comment-respond-form post-id-<?php echo $comment->comment_post_ID; ?> hide">
<table>
<tr>
<form id="custom-comments-form" action="" method="post">
//form fields
<button class="uk-button" type="submit">Send</button>
</form>
</tr>
</table>
</div>
}
的Jquery:
jQuery(function ($) {
$(document).ready(function(){
$(".km-collapse-forms.expand-all").show();
$('.km-collapse-forms.expand-all').on('click',function(){
// Expand/Collapse All
$(".km-collapse-forms.expand-all").addClass("hide");
$(".km-collapse-forms.collapse-all").removeClass("hide");
// Change text respond/hide form
$(".respond-to-messages.expand-form").addClass("hide");
$(".respond-to-messages.collapse-form").removeClass("hide");
$(".comment-respond-form").slideDown("slow");
});
$('.km-collapse-forms.collapse-all').on('click',function(){
$(".km-collapse-forms.collapse-all").addClass("hide");
$(".km-collapse-forms.expand-all").removeClass("hide");
$(".respond-to-messages.collapse-form").addClass("hide");
$(".respond-to-messages.expand-form").removeClass("hide");
$(".comment-respond-form").slideUp("slow");
});
// respond/hide form text :: single comment
// This is where I'm having trouble with
$('.respond-to-messages.expand-form').on('click',function(){
$(this).next(".respond-to-messages.collapse-form").removeClass("hide");
$(this).next(".respond-to-messages.expand-form").addClass("hide");
$(this).next(".comment-respond-form").removeClass("hide");
$(this).next(".comment-respond-form").slideDown("slow");
});
$('.respond-to-messages.collapse-form').on('click',function(){
$(this).next(".respond-to-messages.collapse-form, .comment-respond-form").addClass("hide");
$(this).next(".respond-to-messages.expand-form").removeClass("hide");
$(this).prev(".comment-respond-form").addClass("hide");
$(this).next(".comment-respond-form").slideUp("slow");
});
});
});
如預期,但每一個人Respond to comment/hide form
不同時,我想,要和工作expand/collapse all
工作。
任何幫助,非常感謝。
你能創建的jsfiddle與您的代碼,請。 – andybeli
[link] https://jsfiddle.net/kiarashi/5jkdnzt4/6/ – kiarashi