大家好,我其實正在面臨一個問題我有多個加減div,點擊時應顯示內容。但是當我點擊一個加號圖標時,其他圖標會執行顯示和隱藏內容的操作。多個可摺疊div無法正常工作
<html>
<body>
<div class="expandContent1"><a><h1><img id="arrow1" src="plus.png">One</h1> </a>
</div>
<div class="showMe1" style="display:none">This content was hidden, but now shows up</div>
<script>
var div_show = $('.showMe1'),
arrow = $('#arrow1');
$('.expandContent1').click(function() {
div_show.slideToggle('slow', function() {
if ($(this).is(':visible')) {
arrow.prop('src', 'minus.png');
} else {
arrow.prop('src', 'plus.png');
}
});
});
</script>
</div>
<div class="expandContent2"><a><h1><img id="arrow2" src="plus.png">Two</h1></a>
</div>
<div class="showMe2" style="display:none">This content was hidden, but now shows up</div>
<script>
var div_show = $('.showMe2'),
arrow = $('#arrow2');
$('.expandContent2').click(function() {
div_show.slideToggle('slow', function() {
if ($(this).is(':visible')) {
arrow.prop('src', 'minus.png');
} else {
arrow.prop('src', 'plus.png');
}
});
});
</script>
</body>
</html>
謝謝你的:)不過我應該怎麼做,如果我不得不隱藏其他內容並且一次只顯示一個div,當我們點擊plus時。例如:如果我點擊+ One然後+ Two,則其中一個的內容仍然存在,它不會隱藏。 – user1933852
@ user1933852我已經更新了我的答案。 – Beginner
非常感謝你 – user1933852