javascript jquery如何遍历集合呢?


摘要:
下文讲述jquery遍历集合的方法分享,如下所示;

实现思路:
    使用jquery中$.each方法即可实现遍历集合

例:

 <meta charset='utf-8' />
<p>
maomao365.com<br />
jquery 遍历json对象和数组对象的示例分享
</p>
<hr />
<style>
#msg{
  color:green;
  font-weight:bold;
}
</style>
<script
 src="http://libs.baidu.com/jquery/1.9.0/jquery.js"> 
</script>
<script>
   //jQuery 遍历List集合
    $(function(){  
       var msg = "";   
      var obj =[{"webSiteName":"maomao365","url":"maomao365.com"},{"webSiteName":"linux28","url":"linux28.com"}];  
    $.each(obj,function(n,v) {   
          // alert(n+' '+v);  
            var t = "";  
             t += " <tr> <td> " +v.webSiteName+" </td> <td>" + v.url +"</td > </tr>";  
             msg += t;         
           });  
    $("#msg").append(msg);  
  });

  // jQuery遍历数组 

     $(function(){  
           var msg = "";  
           var arrayList = ['maoamo365.com','linux28.com','other'];  
           $.each(arrayList,function(n,v) {  
               //alert(n+' '+v);  
               var t = "";  
               t += " <tr> <td> " +v+" </td></tr> ";  
               msg += t;  
            });  
          $("#msg").append(msg);  
  });
</script> 
<table id="msg" >
</table>
javascript jquery遍历集合的示例分享

javascript
jquery遍历集合的示例分享