JavaScript-删除last();工作不正常

JavaScript - Removing last() doesn't work correctly?

本文关键字:工作 不正常 删除 last JavaScript-      更新时间:2023-09-26

我有一个移除类的移除函数。它执行正确,除非发现重复

我该如何解决这个问题?这是GIF的

正确:https://gyazo.com/cdd6800f4f847d21d97a071241f76242

重复名称:https://gyazo.com/d166fcf19af8a147fcb2897bfeb695ed

这是代码:

$('li img[title="' + removedname  + '"]:last').parent().parent().removeClass('red lighten-1 white-text selected-item');

HTML

<li class="col 2 zoomIn animated" style="padding: 8px; font-weight: bold; font-size: 16px; animation-delay: 0s;">
   <div class="card item-card waves-effect waves-light red lighten-1 white-text selected-item" data-itemnaaaaaaaaaaaame="★ Butterfly Knife | Crimson Web (Field-Tested)" style="margin: 0%; min-height: 295px; width: 245.438px; border-radius: 15px; height: 245px;" id="2761454276">
      <div class="iteam" style="text-decoration: underline;text-align: left">Butterfly Knife | Crimson Web</div>
      <div class="condition" style="text-align: left;text-size:13px">Field Tested</div>
      <div class="center-align" style="padding:6%">
         <img title="★ Butterfly Knife | Crimson Web (Field-Tested)" draggable="false" src="https://steamcommunity-a.akamaihd.net/economy/image/-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpovbSsLQJf0ebcZThQ6tCvq4iSqODxMajum25V4dB8xLjD9tjwjgK1_kZoYT30ctKVegM7NFyGrwK5yee90ZDt6ZmazHNluCQ8pSGKMl3kzfs/200fx200">
         <div class="" 'floatvalue'="">
            Float: 0.11503319442272186
            <div class="bitskinscomp" style="font-weight: normal;font-size:12px">BitSkins Price: $111.43 (You save: $-38.15)</div>
            <div class="buyer-price center-align">$149.58</div>
         </div>
      </div>
   </div>
</li>

使用最近的而不是:最后的

$('li img[title="' + removedname  + '"]').closest('.card').removeClass('red lighten-1 white-text selected-item');