最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery.each()

jQuery.each( collection, callback(indexInArray, valueOfElement) ) Returns: Object

Description: 一個通用的迭代函數(shù),它可以用來無縫迭代對象和數(shù)組。數(shù)組和類似數(shù)組的對象通過一個長度屬性(如一個函數(shù)的參數(shù)對象)來迭代數(shù)字索引,從0到length - 1。其他對象迭代通過其命名屬性。

  • version added: 1.0jQuery.each( collection, callback(indexInArray, valueOfElement) )

    collection遍歷的對象或數(shù)組。

    callback(indexInArray, valueOfElement)每個成員/元素執(zhí)行的回調(diào)函數(shù)。

$.each()函數(shù)和.each()是不一樣的,這個是專門用來遍歷一個jQuery對象。$.each()函數(shù)可用于迭代任何集合,無論是“名/值”對象(JavaScript對象)或陣列。在一個數(shù)組的情況下,回調(diào)函數(shù)每次傳遞一個數(shù)組索引和相應(yīng)的數(shù)組值。(該值也可以通過訪問this關(guān)鍵字,但是JavaScript將始終包裹this值作為一個Object ,即使它是一個簡單的字符串或數(shù)字值。)該方法返回其第一個參數(shù),這是迭代的對象。

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

這將產(chǎn)生兩個信息:

0: 52
1: 97

如果對象是作為集合使用,回調(diào)函數(shù)每次傳遞一個鍵值對的:

var map = { 
  'flammable': 'inflammable', 
  'duh': 'no duh' 
}; 
$.each(map, function(key, value) { 
  alert(key + ': ' + value); 
});

再次,這將產(chǎn)生兩個信息:

flammable: inflammable
duh: no duh

我們可以打破$.each()返回使得回調(diào)函數(shù)在某一特定的迭代循環(huán)的false 。返回non-false是一樣的一個continue在一個循環(huán)語句,它會立即跳轉(zhuǎn)到下一個迭代。

Examples:

Example: Iterates through the array displaying each number as both a word and numeral

<!DOCTYPE html>
<html>
<head>
  <style>
  div { color:blue; }
  div#five { color:red; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  
  <div id="one"></div>
  <div id="two"></div>
  <div id="three"></div>
  <div id="four"></div>
  <div id="five"></div>
<script>
    var arr = [ "one", "two", "three", "four", "five" ];
    var obj = { one:1, two:2, three:3, four:4, five:5 };

    jQuery.each(arr, function() {
      $("#" + this).text("Mine is " + this + ".");
       return (this != "three"); // will stop running after "three"
   });

    jQuery.each(obj, function(i, val) {
      $("#" + i).append(document.createTextNode(" - " + val));
    });
</script>

</body>
</html>

Demo:

Example: Iterates over items in an array, accessing both the current item and its index.

$.each( ['a','b','c'], function(i, l){
   alert( "Index #" + i + ": " + l );
 });

Example: Iterates over the properties in an object, accessing both the current item and its key.

$.each( { name: "John", lang: "JS" }, function(k, v){
   alert( "Key: " + k + ", Value: " + v );
 });
jQuery 1.6 API 中文版腳本之家整理、修訂 (2011年6月)
望都县| 岳普湖县| 益阳市| 赞皇县| 文化| 社旗县| 平谷区| 禄丰县| 宁阳县| 阳江市| 临沧市| 饶阳县| 金华市| 习水县| 前郭尔| 南宫市| 吴桥县| 萍乡市| 友谊县| 蕲春县| 临清市| 西峡县| 万年县| 成都市| 许昌市| 武城县| 乌拉特前旗| 马龙县| 天台县| 方正县| 东阳市| 比如县| 武陟县| 灵武市| 商洛市| 蒙山县| 阜新市| 西吉县| 昭通市| 和林格尔县| 靖远县|