【问题标题】:How to update nested div and span如何更新嵌套的 div 和 span
【发布时间】:2020-01-06 17:45:50
【问题描述】:

需要更新嵌套的 div 和 span。

HTML:

<table id="item_table" data-role="table">
<thead>
    <tr>
        <th>&nbsp;</th>
        <th scope="col" width="100px">Name</th>
        <th scope="col" width="100px">Address</th>
        <th scope="col" width="150px">Status</th>
    </tr>
</thead>
<tbody>

    <tr class="item" id="APPLE">
        <td>APPLE</td>
        <td width="100px"></td>
        <td width="100px"></td>
        <td width="50px">
        <div id="item-status">
            <img id="status-image" src=""></img>
            <div>
                <span></span>
            </div>
        </div>
        </td>
    </tr>
</tbody>
</table>

如何编写 jquery 代码,以便可以像这样更新行的最后一列。需要更新 id="item-status" 的类并添加 img

<td width="50px">
<div id="item-status" class="not_found">
    <img src="some_image.png"></img>
    <div>
        <span>
            Not found
        </span>
    </div>
</div>

【问题讨论】:

    标签: jquery html


    【解决方案1】:

    这个怎么样:

    $('#item-status').addClass('myNewClass');
    $('#item-status > img').attr('src', 'imagepath');
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <table id="item_table" data-role="table">
      <thead>
        <tr>
          <th>&nbsp;</th>
          <th scope="col" width="100px">Name</th>
          <th scope="col" width="100px">Address</th>
          <th scope="col" width="150px">Status</th>
        </tr>
      </thead>
      <tbody>
        <tr class="item" id="APPLE">
          <td>APPLE</td>
          <td width="100px"></td>
          <td width="100px"></td>
          <td width="50px">
            <div id="item-status">
              <img id="status-image" src="" />
              <div>
                <span></span>
              </div>
            </div>
          </td>
        </tr>
      </tbody>
    </table>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-07
      相关资源
      最近更新 更多