<!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script> <style> </style> </head> <body> <script> $(function(){ var arr=["a", "b", "c"]; var obj={name:"tony", gender:"male", age:18}; var str="Hello World!"; document.write('arr=["a", "b", "c"]<br>'); document.write('obj={name:"tony", gender:"male", age:18}<br>'); document.write('str="Hello World!"<br>'); //測試陣列的 $.each() 迴圈 document.write('$.each(arr, callback) : '); $.each(arr, function(idx, value){ document.write("arr[" + idx + "]=" + value + ", "); }); document.write("<br>"); //測試物件的 $.each() 迴圈 document.write('$.each(obj, callback) : '); $.each(obj, function(key, value){ document.write("obj." + key + "=" + value + ", "); }); document.write("<br>"); //測試物件的 $.each() 迴圈 document.write('$.each(document.location, callback) : '); $.each(document.location, function(key, value){ document.write("document.location." + key + "=" + value + ", "); }); document.write("<br>"); }); </script> </body> </html>