我有這個簡單的jQuery腳本循環通過JSON數組
該腳本不工作在這一切,永遠不會輸出。
確定JSON數組是有效的,但我不知道爲什麼Jquery不解析它。
通過JSON數組簡單的jQuery循環?
$(document).ready(function(){
var cost = [{"gold":"100","iron":"80","wood":"120","food":"70"},{"gold":"80","iron":"60","wood":"90","food":"35"}];
var costarr = $.parseJSON(cost);
$.each(costarr, function(i, item) {
alert(item.gold);
}
});
如果你想玩JavaScript至少使用瀏覽器控制檯來檢查拋出的錯誤...很容易找到你有語法錯誤......它需要3秒鐘的時間來完成它! – charlietfl