我有一个嵌套表结构,其中一部分由从服务器返回 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/