我得到了这个 jquery 手风琴代码:
$(function () {
var icons = {
header: "ui-icon-circle-arrow-e",
activeHeader: "ui-icon-circle-arrow-s"
};
$("#accordion")
.accordion({
header: "> div > h3",
collapsible: true,
active: false,
heightStyle: "content",
icons: icons
})
.sortable({
axis: "y",
handle: "h3",
stop: function (event, ui) {
var items = [];
ui.item.siblings().andSelf().each(function () {
//compare data('index') and the real index
if ($(this).data('index') != $(this).index()) {
items.push(this.id);
}
});
// IE doesn't register the blur when sorting
// so trigger focusout handlers to remove .ui-state-focus
ui.item.children("h3").triggerHandler("focusout");
ui.item.parent().trigger('stop');
}
})
.on('stop', function () {
$(this).siblings().andSelf().each(function (i) {
//kjører for alle "childs" i accordian...
$(this).data('index', i);
});
})
.trigger('stop');
});
这适用于静态 HTML,如下所示:
<div id="accordion">
<div id ="Scene 1" class="group">
<h3><b>#1: Task no 1</b></h3>
<div>
<textarea > Description of first task </textarea>
</div>
<div id ="Scene 2" class="group">
<h3><b>#2: Task no 2/b></h3>
<div>
<textarea> Decription of task</textarea>
</div>
</div>
</div>
但是在通过敲除使 HTML 动态化后,单击标题时手风琴不再展开(或折叠)。
这是淘汰赛/动态 HTML:
<div id="accordion" data-bind="foreach: Tasks">
<div data-bind="attr : {'id': 'Task' + TaskId}" class="group">
<h3><b>#<span data-bind="text: TaskId"></span>: <span data-bind="text: Taskname"></span></b></h3>
<div>
<textarea data-bind="value: Description"></textarea>
</div>
</div>
</div>
谁能看出问题出在哪里?