18910140161

使用JavaScript-Stack溢出为多个元素设置html-set属性

顺晟科技

2022-10-19 11:45:36

10

所以我有表:

<table class="checkout-list">
    <thead>
       <tr>
         <th class="checkout-title">item</th>
         <th class="checkout-title">amount</th>
         <th class="checkout-title">total</th>
       </tr>
     </thead>
     <tbody>
       <tr>
        <td class="checkout-info"></td>
        <td class="checkout-info"></td>
        <td class="checkout-info"></td>
       </tr>
       <tr>
          <td class="checkout-info"></td>
          <td class="checkout-info"></td>
          <td class="checkout-info"></td>
       </tr>
      </tbody>
</table>

使用javascript,我希望从中获取值并将其设置为属性。 我试过:

<table class="checkout-list">
    <thead>
       <tr>
         <th class="checkout-title">item</th>
         <th class="checkout-title">amount</th>
         <th class="checkout-title">total</th>
       </tr>
     </thead>
     <tbody>
       <tr>
        <td class="checkout-info"></td>
        <td class="checkout-info"></td>
        <td class="checkout-info"></td>
       </tr>
       <tr>
          <td class="checkout-info"></td>
          <td class="checkout-info"></td>
          <td class="checkout-info"></td>
       </tr>
      </tbody>
</table>

现在的总线,我只设法为第一个子节点和第二个子节点赋值,但未定义,如下所示:

<table class="checkout-list">
    <thead>
       <tr>
         <th class="checkout-title">item</th>
         <th class="checkout-title">amount</th>
         <th class="checkout-title">total</th>
       </tr>
     </thead>
     <tbody>
       <tr>
        <td class="checkout-info"></td>
        <td class="checkout-info"></td>
        <td class="checkout-info"></td>
       </tr>
       <tr>
          <td class="checkout-info"></td>
          <td class="checkout-info"></td>
          <td class="checkout-info"></td>
       </tr>
      </tbody>
</table>

如何修复此未定义的分配?


顺晟科技:

代码的问题是,只有三个节点with和六个节点with。这就是为什么前3个节点和后3个节点都有值。

您必须访问数组中的节点,这样它才能循环两次标题并正确分配属性

  • TAG:
相关文章
随机推荐
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航