0
JSON看起來是這樣的:如何對數組進行排序並使用HTML進行換行?
[{"title":"Modern\/Contemporary House of mine.","link":"http:\/\/buildworx-mc.com\/forum\/showthread.php?tid=1718","images":["http:\/\/i1139.photobucket.com\/albums\/n555\/xDJBOUTIx\/house1.png","http:\/\/i1139.photobucket.com\/albums\/n555\/xDJBOUTIx\/House2.png","http:\/\/i1139.photobucket.com\/albums\/n555\/xDJBOUTIx\/House3.png","http:\/\/i1139.photobucket.com\/albums\/n555\/xDJBOUTIx\/House4.png","http:\/\/i1139.photobucket.com\/albums\/n555\/xDJBOUTIx\/House5.png","http:\/\/i1139.photobucket.com\/albums\/n555\/xDJBOUTIx\/House6.png"]}
我能拿到冠軍,並鏈接就好了。但我無法得到圖像,因爲在一些有多個鏈接。
我試圖讓每一個圖像鏈接到被包裹在HTML。
$.getJSON("gallery/getScreenshots.php", function (data) {
$.each(data, function (i, image) {
var link = image.link, title = image.title. images = image.images;
$img = $('<img>').attr('src', images);
$('#screenshots').append($img);
});
但結果是這樣的:
<img src="http://i1139.photobucket.com/albums/n555/xDJBOUTIx/house1.png,http://i1139.photobucket.com/albums/n555/xDJBOUTIx/House2.png,http://i1139.photobucket.com/albums/n555/xDJBOUTIx/House3.png,http://i1139.photobucket.com/albums/n555/xDJBOUTIx/House4.png,http://i1139.photobucket.com/albums/n555/xDJBOUTIx/House5.png,http://i1139.photobucket.com/albums/n555/xDJBOUTIx/House6.png" alt="">
我如何排序整個數組,然後獲得每個圖像追加到<img>?
我用你的,我得到未捕獲的SyntaxError:意外的標記, – nowayyy 2012-03-01 03:12:58
其實沒關係,謝謝! – nowayyy 2012-03-01 06:02:53