我正在尝试将帖子图像从div元素移动到另一个div,并使用jquery“prependTo”fiddle
$('.post img').prependTo('.move');
因为我使用了一个类选择器,然后每个图像都会移动并堆放在'move'类的每个元素上
<div class='post-body' expr:id='"post-body-" + data:post.id'>
<div class='move'/>
<div class='post'>
aaa aaa aaa
<img src="image-1"/>
bbb bbb bbb
</div>
</div>
<div class='post-body' expr:id='"post-body-" + data:post.id'>
<div class='move'/>
<div class='post'>
ccc ccc ccc
<img src="image-2"/>
ddd ddd ddd
</div>
</div>
<div class='post-body' expr:id='"post-body-" + data:post.id'/>
<div class='move'/>
<div class='post'>
eee eee eee
<img src="image-3"/>
fff fff fff
</div>
</div>
似乎我应该获得每个帖子的唯一ID,或者是否有解决此问题的方法?
答案 0 :(得分:1)
您不需要发布ID,请尝试此操作
$('.post-body').each(function () {
$(this).find('.post img').prependTo($(this).find('.move'));
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='post-body' expr:id='"post-body-" + data:post.id'>
<div class='move'></div>
<div class='post'>
aaa aaa aaa
<img src="image-1"/>
bbb bbb bbb
</div>
</div>
<div class='post-body' expr:id='"post-body-" + data:post.id'>
<div class='move'></div>
<div class='post'>
ccc ccc ccc
<img src="image-2"/>
ddd ddd ddd
</div>
</div>
<div class='post-body' expr:id='"post-body-" + data:post.id'>
<div class='move'></div>
<div class='post'>
eee eee eee
<img src="image-3"/>
fff fff fff
</div>
</div>
&#13;