我有一些json和jQuery似乎沒有正確選擇其元素。我參考的json文檔可以在這裏找到:http://pastebin.com/bM3BvD2F。用jQuery選擇器選擇JavaScript數組元素項目
json是一個元素數組,我試圖選擇一個需要的ID。
(你可以複製粘貼到http://jsonviewer.stack.hu/爲它的一個很好的摺疊視圖)
這裏是我有問題的代碼:
//get current picture ID - will return '2' - correct value
var currentID = window.location.hash ? window.location.hash.substring(1) : allImages[0]["id"];
//this line will alert name attribute value for a picture with (id = 4) - wrong :(
alert($(allImages[id=currentID])[0].name);
謝謝,這工作! :) – abolotnov 2011-04-03 11:26:00
@abolotnov - 男人你很快! :-) – 2011-04-03 11:27:41