萬盛學電腦網

 萬盛學電腦網 >> 腳本專題 >> javascript >> jquery使用each方法遍歷json格式數據實例

jquery使用each方法遍歷json格式數據實例

   本文實例講述了jquery使用each方法遍歷json格式數據的方法。分享給大家供大家參考。具體實現方法如下:

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script src="jquery-1.6.2.min.js" type="text/javascript"></script> <script type="text/javascript"> //$.each(array,fn)對數組arry每個元素調用fn函數進行處理,沒有返回值 var arr = { "tom": "湯姆", "jerry": "傑瑞", "lily": "莉莉" }; //json格式的對象(dict) $.each(arr, function (key, value) { alert(key + "=" + value); }); //如果是普通風格的數組,則key的值是序號。 </script> </head> <body> </body> </html>

  希望本文所述對大家的jQuery程序設計有所幫助。

copyright © 萬盛學電腦網 all rights reserved