2016-04-30 46 views
-2

我有刪除功能,刪除類。它正確執行,除非它發現重複JavaScript - 正在移除last()無法正常工作?

我該如何解決問題?這裏是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> 
+0

我們需要看到一個更完整的JS和HTML示例能夠幫助您 –

+0

這是刪除它的代碼。 HTML我會再添加一秒。 –

+0

我也添加了我的HTML。 –

回答

-1

最接近的使用,而不是:最後

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

如果我使用它,它不會令人悲傷:/ –

+0

我編輯了代碼。它現在正在搜索'.card'。當我測試它時,類將被刪除。 – Gerard

+0

它將刪除所有具有該名稱的項目的類,因此基本上仍然是相同的:/ –