javascript - 使用某种占位符在 jquery 中查找元素

标签 javascript asp.net jquery html

我有一个嵌套表结构,其中一部分由从服务器返回 HTML 的 ajax 调用呈现。标记如下所示:

.. some html here
        <tr>
          <td><table cellpadding="0" cellspacing="0" border="0">
              <%-- Content will be displayed from ajax call 1 --%>
              <%-- Content will be displayed from ajax call 2 --%>
            </table>
          </td>
        </tr>
    </table>
.. more html

ajax 调用返回以下 html

<tr>
<td class="wpss_checkboxtd"><img width="16" height="16" src="../../images/someimg.png"></td>
</tr>
<tr>
<td class="wpss_checkboxtd"><img width="16" height="16" src="../../images/someimg.png"></td>
</tr>

在 jquery 中,我需要插入此 html,我需要为其遍历一个元素,以便我可以调用该元素的 html()。不幸的是,如果我使用 div,例如:

<table cellpadding="0" cellspacing="0" border="0">
<div id="divAjax1">
              <%-- Content will be displayed from ajax call 1 --%>
</div>
<div id="divAjax2">
              <%-- Content will be displayed from ajax call 2 --%>
</div>
</table>

类的设置使得 div 或 span 会导致其他问题。

我只需要一种方法来确定从 JQuery 中插入此 HTML 的位置。有什么想法吗?

最佳答案

您可以使用多个 <tbody> 部分,并将 ID 放在这些部分上。

这样你就会有有效的 HTML 标记:

<table cellpadding="0" cellspacing="0" border="0">
<thead>
              <!-- header section -->
</thead>
<tbody id="divAjax1">
              <!-- Content will be displayed from ajax call 1 -->
</tbody>
<tbody id="divAjax2">
              <!-- Content will be displayed from ajax call 2 -->
</tbody>
</table>

关于javascript - 使用某种占位符在 jquery 中查找元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4788587/

相关文章:

javascript - 在 css 动画完成之前使 onclick 函数不起作用

c# - ASP.NET MVC 5 Entity Framework - 关系

javascript - 使用 jquery 获取图像 src 时返回未定义

javascript - 将 json 对象数组 POST 到 IHttpHandler

c# - WebDropDown 上的多重选择并将其反射(reflect)在另一个 WebDropDown 中 - Infragistics

c# - 使用 AAD 应用程序访问 Microsoft Graph

javascript - 为什么此 HTML/Javascript 代码不起作用?

jquery - 图像未正确调整大小 - JQuery Backstretch

jquery - iPad 和视差效果

javascript - c3.js 生成图表后更改颜色模式