將值與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 联系我们: