我正在尝试使用AJAX根据在框中选择的内容动态生成JquerUI Accordion。目前我有
<div style="display:none" id="testselect">
</div>使用JS
$("#courseselect").change(function () {
$("#testselect").html(""); // Empty any previous data
$("#testselect").css("display", "block"); // Display it if it was hidden
$.getJSON('json.php?show=tests&courseid=' + $(this).val(), function(data) {
for(x in data)
{
$("#testselect").append("<h3 value=\"" + data[x].uno + "\"><a href=\"#\">" + data[x].name + "</a></h3>");
$("#testselect").append("<div>Foo</div>");
}
$("#testselect").accordion({ change:function(event, ui) { courseid = ui.newHeader.attr("value");
} });
});
});现在,当我第一次更改我的选择时,这是有效的,但之后它将恢复为普通的、未格式化的HTML。就好像对.accordion()的调用从未完成过一样。我猜这与JQuery不想让我格式化某些东西有关,但我真的不知道。
发布于 2011-01-09 09:02:48
在清空div并重新开始之前,尝试销毁accordion:
$("#courseselect").change(function () {
$("#testselect")
.accordion("destroy")
.empty() // equivalent to .html("");
$.getJSON(...更多信息here。
祝好运!
https://stackoverflow.com/questions/4636987
复制相似问题