简体   繁体   English

JavaScript-使用jQuery find作为匹配变量,然后做点什么?

[英]JavaScript - Using jQuery find as matching variable, then doing something?

So I have an Variable which get's item name. 所以我有一个获取项目名称的变量。 I want to do, so it will get item name and then search it from .item card class. 我想这样做,因此它将获取项目名称,然后从.item卡类中进行搜索。 If it matches, then do something.. Is something like that possible to do? 如果匹配,则执行某项操作。是否可以执行类似的操作?

Code to match that item name 匹配该项目名称的代码

var leiaelu = $(".item-card").find("img.title");
leiaelu.removeClass("red lighten-1 white-text selected-item");

Way it get's item name 项目名称的获取方式

var removedname = $(this).text();

Where should I put that removedname variable in that code? 我应该在代码中的那个removename变量放在哪里?

Question is: How could I make that leiaelu match removedname from that class img title. 问题是:我如何让leiaelu匹配该类img标题中的removedname If it is a match, then it does that removeClass line? 如果匹配,则该removeClass行吗?

Here's HTML where is the img title located (original one which it should match) 这是img标题所在的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" 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>

There will be some kind of "amount" of these li classes, which JavaScript adds. JavaScript添加了这些li类的某种“数量”。 All those are stored under one class called: row zmd-hierarchical-display in So there's is that which has to match that removedname.. If it does match, then remove red lighten-1 white-text selected-item from parent class (it will be there, at the moment it is not in that HTML example. 所有这些都存储在一个称为: row zmd-hierarchical-display in因此必须与被删除的名称相匹配。如果确实匹配,则从父类中删除红色lighten-1白色文本selected-item(它将会存在,目前不在该HTML示例中。

I suspect this is what you want: 我怀疑这是您想要的:

$(".item-card").find("img.title").removeClass("red lighten-1 white-text selected-item").each(function() {
    var removedname = $(this).text();
    // do something with removedname
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM