我有一个手风琴,我正在动态创建新元素。但是,当我这样做时,我似乎无法让最新的元素默认打开。它始终是第一个元素。
想法?
这是HTML:
<asp:MultiView ID="MainView" runat="server">
<asp:View ID="View1" runat="server">
<table style="width: 100%; border-width: 3px; border-color: #C4F691; border-style: solid">
<tr>
<td>
<div class="rowClassSpace">
</div>
<div id="accordion">
<a href="#">Make/Model (Insured Vehicle)</a>
<div>
<p>
Content
</p>
</div>
</div>
<div>
<button id="addAccordion">
Add Another Vehicle</button>
</div>
</td>
</tr>
</table>
</asp:View>
</asp:MultiView>
这是JS:
// Initialize accordion
$(document).ready(function () {
$(function () {
$("#accordion").accordion();
});
});
// Adding according sections
$('#addAccordion').click(function () {
});
function addAccordion() {
var active = $('#accordion').accordion('option', 'active');
$('#accordion').append('<a href="#">Make/Model (Other Car #)</a><div><p>New data</p></div>').accordion('destroy').accordion({ active: active});
}