我有手风琴,我想通过ID获取特定标头的索引。
手风琴是由转发器产生的:
<asp:Repeater ID="rptProjectList" OnItemDataBound="rptProjects_ItemDataBound" runat="server">
<HeaderTemplate>
<div id="accordion">
</HeaderTemplate>
<ItemTemplate>
<h1 style="margin: 0px" class="accordionHeader" id='<%# Eval("projectCode") %>'></h1>
<div>
....some stuff
</div>
</ItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
我希望能够在展开特定部分的情况下打开页面,并将projectCode作为参数。例如用户转到MyPage.aspx?project = ABC123,页面加载ABC123项目打开,其他面板折叠。
我拥有的jQuery是:
var activeProject = $(document).getUrlParam("project");
获取代码。
和
$j('#accordion').accordion({
active: activeIndex,
collapsible: true
});
设置手风琴。
我无法弄清楚的是中间位。我需要通过迭代div来获取activeIndex,以获得具有相关项目代码的行的索引。
答案 0 :(得分:6)
var active = $( ".selector" ).accordion( "option", "active" ); //getter
<div id="accordion">
<h3 class='headAcc'>First header</h3>
<div>First content panel</div>
<h3 class='headAcc'>Second header</h3>
<div>Second content panel</div>
</div>
JQuery的
$('#accordion').accordion({
});
//suppose you want to show thee index which starts some text
var indexToActivate = $('.headAcc:contains("Second header")').index();
alert(indexToActivate);
indexToActivate=indexToActivate-1; //index is zero based for jquery ui.
$('button').on('click',function(){
var active = $( "#accordion" ).accordion( "option", "active" ); //getter
alert('Current Index is ' + active +" ");
$( "#accordion" ).accordion( "option", "active",indexToActivate ); //setter
var active = $( "#accordion" ).accordion( "option", "active" ); //getter
alert('Current New Index is ' + active +" ");
});