我有以下 html 结构(这只是一个概述,所有 div 都有内容并正确关闭)。每个 div.views-row 包含一个 views-field-title、views-field-body 和 views-field-afbeeldingen
<div class="view view-toepassingen view-id-toepassingen view-display-id-page view-dom-id-5a6ac8323a7566e5f11218e7b6c49c5c">
<div class="view-content">
<div class="views-row views-row-1 views-row-odd views-row-first">
<div class="views-field views-field-title">
<div class="views-field views-field-body">
<div class="views-field views-field-field-afbeeldingen">
</div>
<div class="views-row views-row-2 views-row-even">
<div class="views-row views-row-3 views-row-odd">
<div class="views-row views-row-4 views-row-even">
<div class="views-row views-row-5 views-row-odd">
<div class="views-row views-row-6 views-row-even views-row-last">
</div>
我想要实现的是将 div 重新排列为:(有效地将标题和正文 div 移动到 'afbeeldingen' div 中,并且对于每个视图行)
<div class="view view-toepassingen view-id-toepassingen view-display-id-page view-dom-id-5a6ac8323a7566e5f11218e7b6c49c5c">
<div class="view-content">
<div class="views-row views-row-1 views-row-odd views-row-first">
<div class="views-field views-field-field-afbeeldingen">
<div class="views-field views-field-title">
<div class="views-field views-field-body">
</div>
</div>
<div class="views-row views-row-2 views-row-even">
<div class="views-row views-row-3 views-row-odd">
<div class="views-row views-row-4 views-row-even">
<div class="views-row views-row-5 views-row-odd">
<div class="views-row views-row-6 views-row-even views-row-last">
</div>
这是我的行为不端的 jquery 代码。我正在尝试遍历所有 6 个视图行 div。
var i = 1;
$('.view-toepassingen > .view-content').children('div').each(function () {
$('.view-toepassingen > .view-content > .views-field-field-afbeeldingen').prepend($('.view-toepassingen > .view-content > .views-row-'+i +' .views-field-title'));
$('.view-toepassingen > .view-content > .views-field-field-afbeeldingen').prepend($('.view-toepassingen > .view-content > .views-row-'+i +' .views-field-body'));
i++;
});