我在 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"));
最佳答案
你可以这样做来改变赔率的顺序,只需改变 child 的顺序
$(function() {
jQuery.each($(".odd"), function() {
$(this).children(":eq(1)").after($(this).children(":eq(0)"));
});
});
这是它工作的 fiddle 。 http://jsfiddle.net/77pHb/
关于jquery - 对于每个奇数表格行,使用 jQuery 切换表格单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14925295/