在WordPress网站上添加了JQuery手风琴,以显示已存档的帖子。当前显示的帖子的列表项由class =“current-article”标识。每个手风琴“标签”都是一个月(当年)或一年。
我编译了JQuery代码,成功打开了当前文章的页面加载选项卡。但是,会出现两个错误:1)第一个选项卡(默认情况下通常为打开状态)在单击并打开另一个选项卡之前无法单击,并且2)我用代码打开的“标签”将不会关闭在第一次点击其他人之后再次点击它。
这是标记:
<div id="accordion">
<h3 tabindex="-1" aria-selected="false" aria-controls="ui-accordion-accordion-panel-0" id="ui-accordion-accordion-header-0" role="tab" class="ui-accordion-header ui-helper-reset ui-state-default ui-accordion-icons ui-corner-all"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-s"></span>June</h3>
<div aria-hidden="true" aria-expanded="false" role="tabpanel" aria-labelledby="ui-accordion-accordion-header-0" id="ui-accordion-accordion-panel-0" style="display: none;" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom">
<ul>
<li><a href="http://linkaddress.co.uk" rel="bookmark" title="Article One">Article One</a></li>
<li><a href="http://linkaddress.co.uk" rel="bookmark" title="Article Two">Article Two</a></li>
</ul>
</div>
<h3 tabindex="0" aria-selected="true" aria-controls="ui-accordion-accordion-panel-1" id="ui-accordion-accordion-header-1" role="tab" class="ui-accordion-header ui-helper-reset ui-state-default ui-accordion-icons ui-accordion-header-active ui-state-active ui-corner-top"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span>May</h3>
<div aria-hidden="false" aria-expanded="true" role="tabpanel" aria-labelledby="ui-accordion-accordion-header-1" id="ui-accordion-accordion-panel-1" style="display: block;" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active">
<ul>
<li class="current current-article"><a href="http://linkaddress.co.uk" rel="bookmark" title="Article Three">Article Three</a></li>
</ul>
</div>
<h3 tabindex="-1" aria-selected="false" aria-controls="ui-accordion-accordion-panel-2" id="ui-accordion-accordion-header-2" role="tab" class="ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ui-accordion-icons"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span>February</h3>
<div aria-hidden="true" aria-expanded="false" role="tabpanel" aria-labelledby="ui-accordion-accordion-header-2" id="ui-accordion-accordion-panel-2" style="display: none;" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom">
<ul>
<li><a href="http://linkaddress.co.uk" rel="bookmark" title="Article Four">Article Four</a></li>
<li><a href="http://linkaddress.co.uk" rel="bookmark" title="Article Five">Article Five</a></li>
</ul>
</div>
</div>
这是我的脚本代码(简单地放在头部):
$(document).ready(function() {
$('h3.ui-accordion-header-active').attr('tabindex', '-1');
$('h3.ui-accordion-header-active').attr('aria-selected', 'false');
$('div.ui-accordion-content-active').prev().removeClass('ui-accordion-header-active ui-state-active ui-corner-top').addClass('ui-corner-all');
$('div.ui-accordion-content-active').css("display","none");
$('div.ui-accordion-content-active').attr('aria-expanded', 'false');
$('div.ui-accordion-content-active').attr('aria-hidden', 'true');
$('div.ui-accordion-content-active').removeClass("ui-accordion-content-active");
$('li.current-article').closest("div").addClass("ui-accordion-content-active");
$('div.ui-accordion-content-active').attr('aria-expanded', 'true');
$('div.ui-accordion-content-active').attr('aria-hidden', 'false');
$('li.current-article').closest("div").css("display","block");
$('div.ui-accordion-content-active').prev().removeClass('ui-corner-all').addClass('ui-accordion-header-active ui-state-active ui-corner-top');
$('h3.ui-accordion-header-active').attr('tabindex', '0');
$('h3.ui-accordion-header-active').attr('aria-selected', 'true');
});
我不是Java专家(正如你可能猜到的那样) - 我只是逐步删除默认“活动”选项卡的“活动”类和属性,并将它们分配给'当前'tab。
我在使用和不使用我的代码时比较了标记或各种状态,看看是否有任何我错过的内容,但我看不出任何差异。
我的问题与我的更改应用时间有关吗?或者我的更改“锁定”在再次单击时会释放的内容?
干杯。
答案 0 :(得分:1)
好的 - 今天学到了更多......而不是试图编辑所有标记,我应该只是模拟一个'点击事件。 Simples。
所以我用这个代替了膨胀的脚本代码:
$(document).ready(function() {
if ($('#accordion').length) {
$('li.current-article').closest("div").prev("h3").click();
}
});
这会查找标有“当前文章”的文章,然后“点击”它关联的h3标题。