我在我的網站上有一個票務系統。有幾個div顯示原始票證,然後在這些div之間嵌套的子隱藏div顯示客戶和工作人員的互動。我想打開一個div,關閉其他div,然後如果他們打開另一個div,所有其他div關閉顯示他們點擊打開的div。jQuery點擊一個DIV並隱藏所有其他DIVS檢測
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");
所以,當他們點擊箭頭,所有其他線程,將關閉,如果打開,箭頭將被重置,這一次將打開。
或者你也可以[創建箭頭(其它形狀)的CSS(http://css-tricks.com/examples/ShapesOfCSS /)! – spinningarrow 2012-07-10 15:57:46
+1 @spinningarrow - 什麼帖子。 – TheBlackBenzKid 2012-07-11 08:49:17