我有一个简单的 jQuery 手风琴,部分标题上有箭头,当部分关闭时指向下方,当部分打开时指向上方。不幸的是,当当前单击某个部分时,所有箭头都切换到向上并保持这种状态。我不太清楚如何解决这个问题。
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>