使用Jquery按钮单击后加载Jquery Accordion

时间:2013-02-13 15:27:14

标签: accordion jquery-ui-accordion

我正在使用JQuery UI Accordion,它可以很好地处理静态内容。但是当我从ajax休息服务电话加载手风琴的H3和Div标签时。数据正常,但手风琴没有加载

onSuccess: function (data) {
        var results = data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results;
        var html = "";

        for (var i = 0; i < results.length; i++) {
            html += "<div><h3><a href=\"#\">";
            html += results[i].Cells.results[3].Value;
            html += "</a></h3><p>"
            html += results[i].Cells.results[6].Value;
            html += "</p></div>";
        }
$("#results_accordion").accordion();

我的Accordion Div最初是空的,我想在按钮点击时填写上述服务电话的数据。

$("#results_accordion").accordion();

任何帮助?

2 个答案:

答案 0 :(得分:0)

$("#results_accordion").html(html).accordion();

在执行手风琴功能

之前,您应首先将html内容添加到您的页面

答案 1 :(得分:0)

这是我的实际点击事件,名为..

function onclic(queryTerms) {

Results = {
    element: '',
    url: '',

    init: function (element) {
        Results.element = element;
        Results.url = someurl;
    },

    load: function () {
        $.support.cors = true;
        $.ajax(
                {
                    url: Results.url,
                    method: "GET",
                    headers: {
                        "accept": "application/json;odata=verbose",
                    },
                    success: Results.onSuccess,
                    error: Results.onError
                }
            );
    },

    onSuccess: function (data) {
        var results = data.d.results;
        var html = "";

        for (var i = 0; i < results.length; i++) {
            html += "<div><h3><a href=\"#\">";
            html += results[i].Cells.results[3].Value;
            html += "</a></h3><p>"
            html += results[i].Cells.results[6].Value;
            html += "</p></div>";
        }


        Results.element.html(html);
        $("#results_accordion").accordion();
    },

    onError: function (err) {
        alert(JSON.stringify(err));
    }
}

Results.init($('#results_accordion'));
Results.load();
$("#results_accordion").accordion();

}