1、循環遍歷標簽
//定義數組 var imagesPath=[]; //循環遍歷對象 $("#uploadList li img").each(function(){ imagesPath.push(this.src.substring(this.src.indexOf("upload/danger"))); }) //數組合並為一個字符串,“、”為字符串連接符 alert(imagesPath.join("、"));
2、循環遍歷數組
var userList = [11,22,33,44]; $.each(userList,function(i,item){ console.log(+i,item); });
用法:$.each() 第一個參數是循環的對象 , 第二個參數對對象中的每一個元素 執行 function函數 ,function 的第一個參數 i 是索引,item 是 循環對象中的每一個元素。