jquery中for循環


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 是 循環對象中的每一個元素。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM