私のサイトにはチケットシステムがあります。元のチケットを表示するいくつかのdivがあり、次にこれらのdivの間にネストされたサブ非表示のdivがあり、顧客とスタッフの相互作用を示します。1つのdivを開き、他のdivを閉じてから、他のdivを開くと、これと他のすべてのdivが閉じて、クリックして開いたdivが表示されます。
jQuery(document).ready(function () {
// ****** Click the ticket DIV
$(".ticket_thread_7").click(function () {
// Slide the SUB DIVs associated with this ticket
$(".ticket_threads_7").slideDown("slow");
// Turn the arrow from DOWN.png to UP.png
$('.ticket_arrow_7').attr("src", "http://cdn.com/assets/imgs/up.png");
// ****** If they have click the arrow again
}, function () {
// .. close this ticket
$(".ticket_threads_7").slideDown("slow");
// .. also return the image back to normal
$('.ticket_arrow_7').attr("src", "http://cdn.com/assets/imgs/up.png");
return false;
});
});
HTML
<div class="ticket_thread_7">
<p>I want to return my order <img src="http://cdn.com/assets/imgs/up.png" class="ticket_arrow_7"></p>
<div class="ticket_threads_7" style="display:none">
<div class="staff_7_1"><p>We cannot accept a return on this item.</p></div>
<div class="cus_7_2"><p>Why not.</p></div>
<div class="staff_7_3"><p>Please visit cdn.com/returnterms to see our policy, apologies.</p></div>
</div>
</div>
この現在のソリューションは正常に機能します。あなたが想像できるように。これは動的なPHP駆動型サイトであるため、サイトには多くのチケットがあります。jQueryで知りたいのですが、コマンドを使用して、ページ上の他のすべてのDIV要素IDを取得し、それらを非表示にできますか。
だから私はこのようなことをすることができます:
// Hide all other current open threads and reset their arrows
$(".ticket_threads_7*!=7").slideDown("slow");
$('.ticket_arrow_'*!=7).attr("src", "http://cdn.com/assets/imgs/up.png");
したがって、矢印をクリックすると、他のすべてのスレッドが開いている場合は閉じ、矢印がリセットされてこのスレッドが開きます。