作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个加载大量数据的 jquery Accordion 。该 Accordion 是通过查询数据库生成的。我的问题 - 有没有办法在单击 Accordion 的特定元素之前不加载内容?基本上,我想将 jquery tab ajax 内容加载的功能复制到 Accordion 。
最佳答案
我正在使用 jquery ui-1.11.4 并遇到了同样的问题。这是我拼凑出来的解决方案。
Javascript:
var already_loaded = new Object(); // used to track which accordions have already been loaded
$(function() {
$( "#accordion" ).accordion({
collapsible: true,
active: false,
//heightStyle: 'fill', // http://jqueryui.com/accordion/#fillspace -- Just sets the height of the accordion to the height of it's parent container. We need a way to change the height of the parent to that of the newly added content.
activate: function (e, ui) {
// only fire when the accordion is opening..
if(ui.newHeader.length>0){
// only retrieve the remote content once..
if(! already_loaded[ui.newHeader[0].id]==1){
var srcObj = $(ui.newHeader[0]).children('a');
var url = srcObj.attr('href');
var folder = srcObj.attr('data-folder');
//$.get(url, function (data){ // if you wanted to use the GET method uncomment this and comment the next line. Be sure to add any needed query string parameters to the URL.
$.post(url, {doCmd:'getFolderFiles', folder:srcObj.attr('data-folder')}, function (data){
$(ui.newHeader[0]).next().html(data);
var contentDiv = $(ui.newHeader[0]).next()[0];
$('#'+contentDiv.id).height(contentDiv.scrollHeight);
//$("#accordion").accordion("refresh"); // http://api.jqueryui.com/accordion/#method-refresh -- The documentation isn't clear on this but this only refreshes added/removed panels. Does not refresh existing panels with newly added content.
already_loaded[ui.newHeader[0].id]=1; // keep track of the loaded accordions
});
}
}
}
});
});
HTML:
<div id="accordion">
<h3><a href="program_to_generate_accordion_content.php" data-folder="2015">2015 Files</a></h3>
<div>
<p>
Loading... Please wait.
</p>
</div>
<h3><a href="program_to_generate_accordion_content.php" data-folder="2016">2016 Files</a></h3>
<div>
<p>
Loading... Please wait.
</p>
</div>
</div>
关于jquery - 如何通过 AJAX 在 JQuery Accordion 中加载内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1880845/
我正在开发一个需要能够平均三个数字的 Facebook 应用程序。但是,它总是返回 0 作为答案。这是我的代码: $y = 100; $n = 250; $m = 300; $number = ($y
我只是无法弄清楚这一点,也找不到任何对我来说有意义的类似问题。我的问题:我从数据库中提取记录,并在我的网页上以每个面板 12 条的倍数显示它们。因此,我需要知道有多少个面板可以使用 JavaScrip
我是一名优秀的程序员,十分优秀!