2013-05-01 50 views
0

我有一個簡單的jQuery手風琴,在部分標題上帶有箭頭,當部分關閉時指向下方,當部分處於打開狀態時指向該部分。不幸的是,當一個部分被點擊時,所有的箭頭都將切換到並保持這種狀態。我無法弄清楚如何解決這個問題。jQuery Accordion HTML箭頭翻轉

JQuery的

function AccordionSelectionClickHandler(panelSelector, openCloseSelector) 
{ 
//Get a handle to the list of panels 
var allPanels = $(panelSelector); 
//Specify the click handler for elements that open or close the accordion panels 

$('.arrow').html("↓"); 
$(openCloseSelector).click(function() 
{ 
    //Close all of the panels 
    allPanels.slideUp(); 

    //Check to see if the slide is already open 
    if ($(this).parent().next().is(':hidden') == true) { 

     // if it is not, open it 
     $(this).parent().next().slideDown('normal'); 
    } 

    // fix this arrow to select a single arrow 
    $('.arrow').html("↑"); 
    return false; 
}); 
} 

(其中panelSelector選擇手風琴和openCloseSelector選擇面板打開/關閉)

HTML

<dl class="accordion"> 

<dt><a href="">Panel 1</a> 
<span class="arrow"></span></dt> 
<dd>Conttent</dd> 

<dt><a href="">Panel 2</a> 
<span class="arrow"></span></dt> 
<dd>Conntent</dd> 

<dt><a href="">Panel 3</a> 
<span class="arrow"></span></dt> 
<dd>Content</dd> 

</dl> 

回答

0

代替$('.arrow').html("&uarr;");嘗試$(this).find('.arrow').html("&uarr;");。這樣,你可以讓jQuery在你點擊的openCloseSelector中找到.arrow

我還建議在if語句中放置$(this).find('.arrow').html("&uarr;");,以便箭頭的文本根據相同的條件而變化。

0

我認爲我們會在dt標籤的背景中使用箭頭圖像並在點擊時改變它的位置來做稍微不同的方式。我做了一些工作讓你明白。

點擊此鏈接查看示例。 JS Fiddle example

此外,請確保您有一個箭頭圖像時取消註釋的CSS。

希望有所幫助。