我有一个div加载了一些HTML。我想要做的是以某种方式从这个div中获得第一个图像(我需要搜索“img”,因为我无法控制他们的类/ ID)并将其作为缩略图放在列表视图中。有任何想法吗? 这是针对Android和iPhone使用jquery/html5的phonegap应用程序。将图像从div加载到ListView中作为缩略图
0
A
回答
1
实施例:
JS:
// Append each image to the list
$('img').each(function() {
var imageList = $('#thumbs');
imageList.append('<li><a href="#"><img src="'+this.src+'"><h3>Thumbnail Title</h3><p>Thumbnail Description</p></a></li>');
});
// Refresh jQM Controls
$('#thumbs').listview('refresh');
HTML:
<!-- images -->
<img src="http://jquerymobile.com/demos/1.1.1/docs/lists/images/album-p.jpg" alt="full size image" />
<img src="http://jquerymobile.com/demos/1.1.1/docs/lists/images/album-xx.jpg" alt="full size image" />
<img src="http://jquerymobile.com/demos/1.1.1/docs/lists/images/album-ok.jpg" alt="full size image" />
<br />
<ul data-role="listview" id="thumbs">
<li><a href="#">
<img src="http://jquerymobile.com/demos/1.1.1/docs/lists/images/album-hc.jpg" />
<h3>Thumbnail Title</h3>
<p>Thumbnail Description</p>
</a></li>
</ul>
0
如你没有提供任何HTML,具有结构像这样
文本这可能会稍微通用
更多的文字
您可以用获取第一张图片继Jquery
$(document).ready(function() {
var html = $("div img:first").attr('src');
$("#list").append("<li><img src="" + html + "" /></li>");
});
This wi将检索div中第一个img标签的src属性并将图像附加到列表中。
这是你之后的事情吗?
相关问题
- 1. 单击缩略图并将图像加载到空div中
- 2. 在ListView中重复图像...从视频加载缩略图
- 3. 从JSON中将缩略图图像加载到UITableView中
- 4. 将缩略图图像从目录加载到PictureBox中
- 5. 将图像文件中的缩略图加载到pixbuf中
- 6. 无法将缩略图加载到ListView中
- 7. jQuery为每个缩略图加载div直到加载
- 8. HOWTO:Long ListView wirh缩略图延迟加载?
- 9. 如果iframe未从URL加载,请加载缩略图图像
- 10. 将图像加载到listview api中
- 11. 快速加载缩略图图像
- 12. 懒惰加载缩略图图像
- 13. 在图像缩略图查看器中预加载图像
- 14. 将图像加载到Div中
- 15. ListView异步图像加载策略
- 16. HTML来jpeg图像作为缩略图
- 17. 将图像显示为缩略图
- 18. Woocommerce遇到问题将缩略图加载为主要产品图像
- 19. 加载图像从URL到的ListView
- 20. Android从URL加载图像到ListView
- 21. 从URL加载图像到ListView
- 22. 从url加载图像到android listview
- 23. 在将图像从SD加载到ListView时提高ListView效率
- 24. 为什么在ListView中自动设置缩略图图像
- 25. 如何在SWT中添加图像作为缩略图
- 26. 使用jQuery缩略图滚轮和加载图像到一个div
- 27. 使用AsyncTask bug将位图缩略图加载到RecyclerView中
- 28. 如何从DateBase中将图像加载到ListView中?
- 29. 将图像缩略图添加到网格中的布局?
- 30. 如何将缩略图图像的数量增加到FlexSlider中
已任何示例代码共享? – shanabus 2012-07-31 13:08:47