JQueryUI 手风琴式重新设计

发布于 2024-10-11 09:56:08 字数 1718 浏览 2 评论 0原文

我正在更改手风琴结构 () 并根据使用 AJAX 的选择来更改它。

问题是,根据手风琴文档,我希望它像

<h3>header</h3>
<div><anything></anything></div>

让 h3 填充标题和 div 填充主体一样工作,但是当我使用 ajax 动态创建它时,它会搞砸。此代码专门为第一个手风琴框使用正确的标题,但正文为空,下一个标题变为“没有打开的会话窗口...”,这显然不是我想要的。得到的 JSON 在这里: http://benbuzbee.com/trs/ json.php?show=sessions&courseid=5

$(function() { 
    $("#courseselect").change(function () {

        $("#testselect").accordion("destroy").html(""); // Empty any previous data
        $("#testselect").css("display", "block"); // Display it if it was hidden

        $.getJSON('json.php?show=sessions&courseid=' + $(this).val(), function(data) {
            for (x in data)
            {
                $("#testselect").append("<h3><a href=\"#\">" + data[x].name + "</a></h3>");
                $("#testselect").append("<div>");
                if (!data[x].sessions)
                    $("#testselect").append("<p>There are no open session windows for this test.</p>");
                for (si in data[x].sessions)
                {
                    $("#testselect").append("<a href=registerconfirm.php?sessionid=\""+data[x].sessions[si].uno+"\">"+data[x].sessions[si].location+"</a>");
                }
                $("#testselect").append("</div>");
            }
            $("#testselect").accordion();
            //$("#testselect").accordion({ change:function(event, ui) {  courseid = ui.newHeader.attr("value"); }
        }); // End getJSON 
     }); // end .change
}); // end $()

I am changing an accordion structure () and changing it based on a choice using AJAX.

The problem is, based on the accordion docs, I expect it to work like

<h3>header</h3>
<div><anything></anything></div>

Making the h3 stuff the header and the div stuff the body, but when I use ajax to dynamically create it it screws up. This code specifically uses the correct header for the first accordion box, but the body is empty and the next header becomes "There are no open session windows..." which is clearly not what I wanted. The JSON this gets is here: http://benbuzbee.com/trs/json.php?show=sessions&courseid=5

$(function() { 
    $("#courseselect").change(function () {

        $("#testselect").accordion("destroy").html(""); // Empty any previous data
        $("#testselect").css("display", "block"); // Display it if it was hidden

        $.getJSON('json.php?show=sessions&courseid=' + $(this).val(), function(data) {
            for (x in data)
            {
                $("#testselect").append("<h3><a href=\"#\">" + data[x].name + "</a></h3>");
                $("#testselect").append("<div>");
                if (!data[x].sessions)
                    $("#testselect").append("<p>There are no open session windows for this test.</p>");
                for (si in data[x].sessions)
                {
                    $("#testselect").append("<a href=registerconfirm.php?sessionid=\""+data[x].sessions[si].uno+"\">"+data[x].sessions[si].location+"</a>");
                }
                $("#testselect").append("</div>");
            }
            $("#testselect").accordion();
            //$("#testselect").accordion({ change:function(event, ui) {  courseid = ui.newHeader.attr("value"); }
        }); // End getJSON 
     }); // end .change
}); // end $()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瀟灑尐姊 2024-10-18 09:56:08

我想我看到了一些问题。

您的语句

$("#testselect").append("<div>") 

将向 #testSelect 附加开始和结束标记,如下所示:

 <div id='testselect'><h3><a> </a> </h3><div></div> </div>

任何进一步附加到 #testselect 的操作都将在 div 标记之后附加元素。

您的下一条语句

$("#testselect").append("<p>There are no open session windows for this test.</p>");

将执行此操作

   <div id='testselect'><h3><a></a></h3><div></div><p> There are no open session windows for this test. </p> </div>

您的语句

$("#select.").append("</div>") 

不会像您打算的那样将结束 div 标签附加到 #testselect。相反,它什么也不做。

您应该将 for 循环更改为如下所示:

for (x in data)
{
     var $header = $("<h3>").appendTo("#testSelect");
     $header.append("<a href=\"#\">" + data[x].name + "</a>")
     var messageContainer = $("<div>").appendTo($header);
     if (!data[x].sessions)
           messageContainer.append("<p> There are no open session windows for this test </p>");
           for (si in data[x].sessions)
           {
                  messageContainer.append("<a href=registerconfirm.php?sessionid=\""+data[x].sessions[si].uno+"\">"+data[x].sessions[si].location+"</a>");
           }
           $("#testselect").accordion();
}

I think I see a few problems.

Your statement

$("#testselect").append("<div>") 

will append BOTH an opening and a closing tag to #testSelect like this:

 <div id='testselect'><h3><a> </a> </h3><div></div> </div>

Any further appending to #testselect will append elements AFTER the div tags.

Your next statement,

$("#testselect").append("<p>There are no open session windows for this test.</p>");

Will do this

   <div id='testselect'><h3><a></a></h3><div></div><p> There are no open session windows for this test. </p> </div>

Your statement

$("#select.").append("</div>") 

will NOT append a closing div tag to #testselect like you seem to be intending. Instead, it will do nothing.

You should change your for loop to something like this:

for (x in data)
{
     var $header = $("<h3>").appendTo("#testSelect");
     $header.append("<a href=\"#\">" + data[x].name + "</a>")
     var messageContainer = $("<div>").appendTo($header);
     if (!data[x].sessions)
           messageContainer.append("<p> There are no open session windows for this test </p>");
           for (si in data[x].sessions)
           {
                  messageContainer.append("<a href=registerconfirm.php?sessionid=\""+data[x].sessions[si].uno+"\">"+data[x].sessions[si].location+"</a>");
           }
           $("#testselect").accordion();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文