each遍历

<script>

    $(function () { 
        $.each([52, 97], function(index, value) {
          alert(index + ': ' + value);
            });
    })

</script>    

假设页面上有这样一个简单的无序列表。

1
2
3
4
<ul>
<li>foo</li>
<li>bar</li>
</ul>

你可以选中并迭代这些列表:

1
2
3
$( "li" ).each(function( index ) {
console.log( index + ": "" + $(this).text() );
});

列表中每一项会显示在下面的消息中:

0: foo 
1: bar

 

原文地址:https://www.cnblogs.com/jiefangzhe/p/10779435.html