我在 CMS 中工作,几乎无法控制 HTML。我依靠 jQuery 来操作这个表。我的客户想要为每一行交替标题和图像。
所需的布局看起来有点像这样:
[Image][Title]
[Title][Image]
[Image][Title]
[Title][Image]
这是我正在使用的简化版本:
<tbody>
<tr class="odd">
<td class="views-field-title"></td>
<td class="views-field-field-services-image-fid"></td>
<td class="views-field-value0"></td>
</tr>
<tr class="even">
<td class="views-field-title"></td>
<td class="views-field-field-services-image-fid"></td>
<td class="views-field-value0"></td>
</tr>
<tr class="odd">
<td class="views-field-title"></td>
<td class="views-field-field-services-image-fid"></td>
<td class="views-field-value0"></td>
</tr>
<tr class="even">
<td class="views-field-title"></td>
<td class="views-field-field-services-image-fid"></td>
<td class="views-field-value0"></td>
</tr>
</tbody>
我是 jQuery 新手,一直在努力使用 .each() 函数。这是我所能得到的:
$(".views-field-title").after($(".views-field-field-services-image-fid"));