Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有无限数量
<div class="item-1">text</div> <div class="item-2">text</div> <div class="item-3">text</div> <div class="item-4">text</div> <div class="item-5">text</div> ...
我想搜索所有可用的div并将它们存储在带有 jQuery 的数组中。
div
您可以使用通配符,以selector开头。
arr = $('[class^=item-]');
现场演示
arr = $('[class^=item-]'); arr.each(function(){ alert($(this).text()); });