我真的不知道到底我错了图像。可能很简单,但我无法弄清楚。任何帮助将是伟大的,请和谢谢。检索JSON文件,该文件是在数据库和显示HTML img标签
JSON代码(它被存储在 '图像' 列在数据库tblproducts表)
{"200x200":"http://img.fkcdn.com/image/mobile/p/s/u/lenovo-k6-power-k33a42-200x200-imaezt6hypjzhdug.jpeg","400x400":"http://img.fkcdn.com/image/mobile/p/s/u/lenovo-k6-power-k33a42-400x400-imaezt6hypjzhdug.jpeg","800x800":"http://img.fkcdn.com/image/mobile/p/s/u/lenovo-k6-power-k33a42-800x800-imaezt6hypjzhdug.jpeg","unknown":"http://img.fkcdn.com/image/mobile/p/s/u/lenovo-k6-power-k33a42-original-imaezt6hypjzhdug.jpeg"}
HTML & PHP代码:
$category_id = $_GET['category_id'];
$result = mysql_query("select * from tblproducts where category_id = '$category_id");
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
?>
var data =
data.forEach(function(obj) {
var img = new Image();
img.src = obj.Img1;
img.setAttribute("class", "banner-img");
img.setAttribute("alt", "effy");
document.getElementById("img-container").appendChild(img);
});
我不知道的JavaScript,以及如何想法从json中获取每个图像并将其显示在不同的标签中。请帮助...在此先感谢
+0
该json包含多个不同大小的图像。你想要多大的尺寸? –
+0
我必须将它们中的每一个取出并显示在不同的img标签中,怎么办? –