Home  >  Article  >  Web Front-end  >  jQuery traverses objects, arrays, and collection instances_jquery

jQuery traverses objects, arrays, and collection instances_jquery

WBOY
WBOYOriginal
2016-05-16 16:32:051796browse

1.jquery traverse objects

Copy code The code is as follows:




New Document







                                                                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                                                                                          
UsernamePassword







2.jQuery traverses arrays

Copy code

The code is as follows:

 
 
  
  New Document  
   
   
     $(function(){ 
 
       var tbody = ""; 
     
     //------------遍历数组 .each的使用------------- 
           var anArray = ['one','two','three']; 
     $("#result").html("------------遍历数组 .each的使用-------------"); 
           $.each(anArray,function(n,value) { 
            
            alert(n ' ' value); 
           var trs = ""; 
             trs = "" value ""; 
              tbody = trs; 
            }); 
 
          $("#project").append(tbody); 
      
  }); 
   
  
  
  
    ------------此部分同1中的body部分-------------------- 
 
  

3.jQuery 遍历List集合(其实与遍历一个对象没有太大区别,只是格式上的问题) 

复制代码 代码如下:
 
 
 
  
  New Document  
   
   
     $(function(){ 
 
       var tbody = ""; 
     
     //------------遍历List集合 .each的使用------------- 
      var obj =[{"name":"项海军","password":"123456"},{"name":"科比","password":"333333"}]; 
    $("#result").html("遍历List集合 .each的使用"); 
      alert(obj);//是个object元素 
   //下面使用each进行遍历 
   $.each(obj,function(n,value) {  
           alert(n ' ' value); 
       var trs = ""; 
             trs = "" value.name " " value.password ""; 
             tbody = trs;        
           }); 
         $("#project").append(tbody); 
      
  }); 
   
  
  
  
       ------------此部分同1中的body部分-------------------- 
 
  

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn