簡體   English   中英

使用Prototype - javascript在嵌套表中選擇基於類的td

[英]Selecting td's based on class in a nested table using Prototype - javascript

我正在研究一些在另一個表中有一個表的遺留代碼。 兩者都有ID。 我需要在該嵌套表中選擇具有特定類屬性的tds。 這是使用Prototype ...再次作為遺留代碼的副產品。 我怎樣才能選擇所有特定的tds並遍歷它們?


<table>
<tr><td></td><td></td></tr>
  <tr><td colspan="2">
    <table id="tableIWant">
      <tr>
         <td class="classIWant"></td>
         <td class></td>
         <td class="classIWant"></td>
         <td class></td>
      </tr>
     </table>
    </td>
   </tr>
 </table>

所以我想使用Prototype框架在id =“tableIWant”的表中選擇class =“classIWant”的所有tds。 我怎么能這樣做?

- 感謝新手工程師。

使用$$在Prototype中選擇CSS樣式選擇器。

var allTds = $$('#tableIWant td.classIWant');

迭代然后:

allTds.each(function(td) {
    // Set background to red on selected tds.
    td.style.background = '#f00';
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM