标签:bsp 测试 for javascrip 调用 html console func 执行
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>遍历方法的测试</title> 6 <script type="text/javascript" src="../js/jquery-1.11.0.js"></script> 7 <script> 8 var cities = ["南京","苏州","无锡","常州"]; 9 10 //方法一:自己就执行了,不用调用 11 $(cities).each(function(i,n){ 12 console.log(i+"---"+n); 13 }); 14 15 //方法二:也是自己就执行了 16 $.each(cities,function(i,n){ 17 console.log(i+"---"+n); 18 }); 19 20 //方法三:自己实现一个,需要手动调用 21 function myEach(array,callback){ 22 for(var i=0;i<array.length;i++){ 23 callback(i,array[i]); 24 } 25 } 26 27 function callback(i,n){ 28 console.log(i+"---"+n); 29 } 30 31 myEach(cities,callback); 32 33 </script> 34 </head> 35 <body> 36 </body> 37 </html>
标签:bsp 测试 for javascrip 调用 html console func 执行
原文地址:https://www.cnblogs.com/yxfyg/p/12676537.html