我有一个图像 div .. 例如:
<div class="image-container">
<img width="174" height="174" src="http://mysite.com/images/portfolio/p1.jpg" class="image-style" typeof="foaf:Image">
<img width="174" height="174" src="http://mysite.com/images/portfolio/p2.jpg" class="image-style" typeof="foaf:Image">
<img width="174" height="174" src="http://mysite.com/images/portfolio/p3.jpg" class="image-style" typeof="foaf:Image">
<img width="174" height="174" src="http://mysite.com/images/portfolio/p4.jpg" class="image-style" typeof="foaf:Image">
</div>
我想使用 jQuery 遍历每个图像并使其成为 div 然后将图像指定为背景图像......像这样:
<div class="image-container">
<div style="background-image:url(http://mysite.com/images/portfolio/p1.jpg)"><span>image</span></div>
<div style="background-image:url(http://mysite.com/images/portfolio/p2.jpg)"><span>image</span></div>
<div style="background-image:url(http://mysite.com/images/portfolio/p3.jpg)"><span>image</span></div>
<div style="background-image:url(http://mysite.com/images/portfolio/p4.jpg)"><span>image</span></div>
</div>
我知道如何为一个人执行此操作,但不确定浏览父 div ( image-container
) 中的所有图像并转换它们的最佳方法。
任何帮助将不胜感激。C