将值与li元素进行比较

[英]compare the value with li element


I have the node id and append to the div.I want to check the node id which id in div with the class 'node_id'. and compare the id with li which is having the class name which is equal to class 'node_id'.I have the parent list with class="flex-active-slider".inside parent list I want to take the value with the class="node_id" and check the list which is having the same value. and increase the width of the img inside it

我有节点id并附加到div.I想要检查节点id在div中使用类'node_id'的id。并将id与li进行比较,其中类名等于class'node_id'。我的父列表中包含class =“flex-active-slider”.inside parent list我想用class =取值“node_id”并检查具有相同值的列表。并增加其内部的img的宽度

<li class="flex-active-slider">
  <div class="test"></div>
  <div class="node_id"><span>233</span></div>  //compare 233
  <ul>
     <li class="69"><img></li>
     <li class="233"><img></li>  // increase width
     <li class="299"><img></li>
  </ul> 
</li>

2 个解决方案

#1


1  

Use $.text() on the .node_id element to get the value, then use that value to target the li with the class that matches.

在.node_id元素上使用$ .text()来获取值,然后使用该值将li与匹配的类作为目标。

var node_id = $('.node_id').text();
$('.'+node_id).find('img').css('width','100px');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li class="flex-active-slider">
  <div class="node_id"><span>233</span></div>
  <ul>
     <li class="69"><img></li>
     <li class="233"><img></li>
     <li class="299"><img></li>
  </ul> 
</li>

#2


0  

The data info. should not be saved inside class attribute, store the data into data-* attribute instead. The data-* attributes are used to store custom data private to the page or application.

数据信息。不应该保存在class属性中,而是将数据存储到data- *属性中。 data- *属性用于存储页面或应用程序专用的自定义数据。

https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes

https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes

In your case, the node_id should be store inside data-node-id attribute.

在您的情况下,node_id应存储在data-node-id属性中。

To answer your question,

要回答你的问题,

  1. Get the target node ID
  2. 获取目标节点ID
  3. Find the li element with the save node ID
  4. 使用保存节点ID查找li元素
  5. Reset the previously assigned class (Optional)
  6. 重置以前分配的类(可选)
  7. Alter the class if target found
  8. 如果找到目标,则更改班级

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2017/02/22/19af1b809b60b7c2d10d0a16ca4c6993.html



 
  © 2014-2022 ITdaan.com 联系我们: