gpt4 book ai didi

javascript - jQuery 加载具有特定类的前十个元素

转载 作者:太空宇宙 更新时间:2023-11-04 14:06:54 24 4
gpt4 key购买 nike

我试图加载的页面是这样的(尽管每次“文本”类的段落数都不同):

<html>
<body>
<div id="container">
<p class="text">1</p>
<p class="text">2</p>
<p class="text">3</p>
<p class="text">4</p>
<p class="text">5</p>
<p class="text">6</p>
<p class="text">7</p>
<p class="text">8</p>
<p class="text">9</p>
<p class="text">10</p>
<p class="text">11</p>
<p class="text">12</p>
<p class="text">13</p>
<p class="text">14</p>
<p class="text">15</p>
<p class="text">16</p>
<p class="text">17</p>
<p class="text">18</p>
<p class="text">19</p>
<p class="text">20</p>
<p class="sometext">Some other text here</p>
</div>
</body>
</html>

是否可以使用类似 $('#text').load('other_file.html #container .p'); 的 jQuery 仅加载前十段?

最佳答案

使用 :lt()选择器。它是从 0 开始的,所以 p:lt(10) 应该加载前 10 个 p 元素。

$('#text').load('other_file.html #container p:lt(10)');

请记住,整个响应仍在下载中,只有一个小节通过选择器显示。

关于javascript - jQuery 加载具有特定类的前十个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8650589/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com