You could use prevAll()(您可以使用prevAll())
console.log($('.p16').prevAll('.loader').length)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="loader p12"></div> <div class="loader p13"></div> <div class="loader p14"></div> <div class="loader p15"></div> <div class="loader p16"></div> <div class="loader p17"></div> <div class="loader p18"></div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…