2

我有一些 Json 数据,其中包含带有一些关联值的产品图像。我想获取该json数据,将其存储在“li”中并使用jquery附加到某个div。请告诉我如何将图像附加到 li。这是Json数据

{"url":"1.jpg","color":"Yellow","Item":"Item A","sold_out":"1"},{"url":"2.jpg","color ":"Red","Item":"Item B","sold_out":"0"},{"url":"3.jpg","color":"Green","Item":"Item D ","sold_out":"0"},{"url":"4.jpg","color":"Red","Item":"Item A","sold_out":"1"},{" url":"5.jpg","color":"Blue","Item":"Item B","sold_out":"0"}

4

3 回答 3

2

使用循环遍历json$.each并将其附加到html元素(li)。

示例(未测试

$.each(data, function(key, val) {
    $("ul").append("<li><img src=\"https://path/" + data[key].url+ "\" /></li>");
});

data是 json 数组。希望能帮助到你。

于 2012-10-09T09:06:40.590 回答
1

将图像附加到列表

var myImageSrc = "1.jpg";
var myList = $('#mylist');
myList.append('<li><img src="' + myImageSrc + '" /></li>');
于 2012-10-09T09:06:16.473 回答
0

这是您想要的 JSFiddle更新 http://jsfiddle.net/Rm4vE/4/

于 2012-10-09T09:03:17.853 回答