HTML:
<h3>對象數組顯示</h3> <table id="obj" border="1"> </table>
jquery:
var animals = [ { 'name':'dog', 'mouse':'wangwang..' }, { 'name':'cat', 'mouse':'miaomiao..' }, { 'name':'pig', 'mouse':'nene...' }, { 'name':'bird', 'mouse':'jiji..' }, ]; $.each(animals, function(index,value){ $('table#obj').append('<tr><td>'+value.name+'</td><td>'+value.mouse+'</td></tr>'); });
運行結果:
知識點:
1,json