【问题标题】:JQueryUI calling .accordion twice on one idJQueryUI 在一个 id 上调用 .accordion 两次
【发布时间】:2011-01-09 00:27:11
【问题描述】:

我正在尝试使用 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 不希望我格式化两次有关,但我真的不知道。

【问题讨论】:

    标签: javascript jquery jquery-ui


    【解决方案1】:

    在清空 div 并重新开始之前尝试销毁手风琴:

    $("#courseselect").change(function () {
        $("#testselect")
            .accordion("destroy")
            .empty() // equivalent to .html("");
        $.getJSON(...
    

    更多信息here

    祝你好运!

    【讨论】:

    • 啊,太好了。找了个方法销毁,没想到是.accordion的参数,谢谢!
    猜你喜欢
    • 2015-04-13
    • 1970-01-01
    • 2022-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多