如何在每个博客帖子上获取唯一ID

时间:2018-06-17 14:15:11

标签: jquery blogger

我正在尝试将帖子图像从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,或者是否有解决此问题的方法?

1 个答案:

答案 0 :(得分:1)

您不需要发布ID,请尝试此操作

&#13;
&#13;
$('.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;
&#13;
&#13;