【发布时间】:2020-10-22 10:28:28
【问题描述】:
我想做的是 Ajax 页面中的前五个手风琴元素。通过 ajax 加载现有内容后,我无法将现有内容保持为手风琴格式。是否可以使用 .load() 仅拉出前五名?我该如何解决这个问题?
我想从以下位置 ajax 的页面:
<div id="main" class="accordians">
<h3>Collapsible Group Item #1</h3>
<div>
<p>This is section 1. Place your content here in paragraphs or use div elements etc.</p>
</div>
<h3>Collapsible Group Item #2</h3>
<div>
<p>This is section 2. Place your content here in paragraphs or use div elements etc.</p>
</div>
<h3>Collapsible Group Item #3</h3>
<div>
<p>This is section 3. Place your content here in paragraphs or use div elements etc.</p>
</div>
<h3>Collapsible Group Item #4</h3>
<div>
<p>This is section 4. Place your content here in paragraphs or use div elements etc.</p>
</div>
<h3>Collapsible Group Item #5</h3>
<div>
<p>This is section 5. Place your content here in paragraphs or use div elements etc.</p>
</div>
<h3>Collapsible Group Item #6</h3>
<div>
<p>This is section 6. Place your content here in paragraphs or use div elements etc.</p>
</div>
</div>
第二页将通过 Ajax 拉手风琴:
<div id="load-top-five">#load top five accordions into here.</div>
<script>
// would like to combine the functionality to only return the top five.
$('#load-top-five').load('https://www.example.com #main'); // this loads the page but doesn't keep it in the correct format.
$('#load-top-five').find('#main:lt(5)').each(function(){...} // I would like to do some logic like this to only render the top 5.
<script>
【问题讨论】:
标签: javascript jquery ajax jquery-ui-accordion