2013-05-01 109 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。

希望有所帮助。