好的,所以我用HTML制作网站,效果很好,但我需要知道如何在JavaScript页面上显示图像。我在我的网站上在主页上有一部分叫做新闻,它将显示关于该主题的图像,但我不知道如何显示图像。当我使用其他网站的方式时,图像只显示为带有?在中间。请帮忙!!用Javascript显示图像
0
A
回答
0
这将工作:
的javascript:
var i = document.getElementById('test'); //get the element to put the picture in
i.innerHTML = '<img src="http://pathtopicture.jpg"></img>'; // append the picture to the divs inner HTML
HTML:
<div id="test"></div>
或者没有HTML摆在首位(当然你需要html和body标签...)
代码:
var i = document.createElement('div');
i.id = 'test';
document.getElementsByTagName('body')[0].appendChild(i);
i.innerHTML = '<img src="http://pathtopicture.jpg"></img>';
0
var img = document.createElement("img");
img.src = src;
img.width = width;
img.height = height;
img.alt = alt;
var theDiv = document.getElementById("<ID_OF_THE_DIV>");
theDiv.appendChild(content);
我这些回答来自:
How to display image with javascript?
How to append data to div using javascript?
相关问题
- 1. 用javascript显示CAD图像
- 2. 使用JavaScript显示图像
- 3. 用javascript显示图像
- 4. Javascript,显示透明图像。
- 5. Javascript显示已选图像
- 6. JavaScript显示图像逐一
- 7. Javascript显示本地图像
- 8. javascript图像不显示
- 9. 图像显示在JavaScript中
- 10. 图像不显示在javascript
- 11. 使用javascript和CSS显示图像
- 12. 如何使用Javascript显示图像?
- 13. 使用PHP和Javascript的图像显示
- 14. 用JavaScript显示图像问题
- 15. 仅使用javascript显示图像
- 16. 用javascript在图像上显示文本
- 17. 用javascript动态显示XML图像
- 18. 使用JavaScript显示图像FileReader
- 19. 如何使用javascript显示图像
- 20. 用javascript显示图像需要帮助
- 21. 使用Javascript vs HTML来显示图像
- 22. 使用JavaScript来显示图像
- 23. 用JavaScript显示/隐藏图像
- 24. 在面具下显示图像css/javascript
- 25. JavaScript:如何显示压缩图像
- 26. JavaScript代码错误:图像不显示
- 27. JavaScript幻灯片显示所有图像
- 28. 在Javascript中显示数据库图像
- 29. 的Javascript CSS图像不显示
- 30. 来自uri的Javascript显示图像