出于某种原因,我无法使用存储在数据活动属性中的数据激活手风琴面板?
我的 HTML 看起来像这样(在它变成手风琴并添加了所有类之后):
<div class="gcAccordion ui-accordion ui-widget ui-helper-reset" style="" data-active="1" role="tablist">
<h3 class="gcAccordionTitle ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ui-accordion-icons" style="display: block;" role="tab" id="ui-accordion-1-header-0" aria-controls="ui-accordion-1-panel-0" aria-selected="false" tabindex="0"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span>This is a title</h3>
<div class="gcAccordionContent ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" style="display: none;" id="ui-accordion-1-panel-0" aria-labelledby="ui-accordion-1-header-0" role="tabpanel" aria-expanded="false" aria-hidden="true">This is some content</div>
<h3 class="gcAccordionTitle ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ui-accordion-icons" style="display: block;" role="tab" id="ui-accordion-1-header-1" aria-controls="ui-accordion-1-panel-1" aria-selected="false" tabindex="-1"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span>This is a 2nd title</h3>
<div class="gcAccordionContent ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" style="display: none;" id="ui-accordion-1-panel-1" aria-labelledby="ui-accordion-1-header-1" role="tabpanel" aria-expanded="false" aria-hidden="true">This is some 2nd content</div>
<h3 class="gcAccordionTitle ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ui-accordion-icons" style="display: block;" role="tab" id="ui-accordion-1-header-2" aria-controls="ui-accordion-1-panel-2" aria-selected="false" tabindex="-1"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span>This is a 3rd title</h3>
<div class="gcAccordionContent ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" style="display: none;" id="ui-accordion-1-panel-2" aria-labelledby="ui-accordion-1-header-2" role="tabpanel" aria-expanded="false" aria-hidden="true">This is some 3rd content</div>
</div>
Javascript:
$('.gcAccordion').accordion({
collapsible: true,
heightStyle: "content",
autoHeight: false,
active: false,
create: function(event, ui){
$('.gcAccordion').each(function(){
console.log($(this).attr('data-active'));
$(this).accordion( "option", "active", $(this).attr('data-active'));
});
}
});
console.log 调用正确地将 1 输出到日志,但由于某种原因,它没有激活第二个面板。如果我将此行用于 javascript 中的第 9 行,则它可以工作:
$(this).accordion( "option", "active", 1);
但它不适用于数据活动属性 1 值。有什么想法吗?
编辑:删除链接,因为该页面不再处于活动状态,并且所有代码都在问题中。
更新:
谢谢您的帮助。我需要parseInt($(this).attr('data-active'))