1 回答
TA贡献1820条经验 获得超2个赞
您可以遍历每个data-group数字,并仅选择组中的第一个:
for (let i = 1; i < 4; i++) {
$(`[data-group=${i}]`).first().css("border", "blue solid 2px")
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="groups"> <!-- or something -->
<div class="row mt-2" data-group="1">Group 1</div>
<div class="row mt-2" data-group="1">Group 1</div>
<div class="row mt-2" data-group="1">Group 1</div>
<div class="row mt-2" data-group="2">Group 2</div>
<div class="row mt-2" data-group="2">Group 2</div>
<div class="row mt-2" data-group="3">Group 3</div>
<div class="row mt-2" data-group="3">Group 3</div>
<div class="row mt-2" data-group="3">Group 3</div>
<div class="row mt-2" data-group="3">Group 3</div>
</div>
添加回答
举报