JQueryUI 手风琴式重新设计
我正在更改手风琴结构 () 并根据使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我看到了一些问题。
您的语句
将向 #testSelect 附加开始和结束标记,如下所示:
任何进一步附加到 #testselect 的操作都将在 div 标记之后附加元素。
您的下一条语句
将执行此操作
您的语句
不会像您打算的那样将结束 div 标签附加到 #testselect。相反,它什么也不做。
您应该将 for 循环更改为如下所示:
I think I see a few problems.
Your statement
will append BOTH an opening and a closing tag to #testSelect like this:
Any further appending to #testselect will append elements AFTER the div tags.
Your next statement,
Will do this
Your statement
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: