亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jquery的$().each和$.each的區(qū)別

 更新時(shí)間:2019年01月18日 09:51:05   作者:muzidigbig  
今天小編就為大家分享一篇關(guān)于jquery的$().each和$.each的區(qū)別,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧

$(selector).each(function(index,element))

這個(gè)函數(shù)和之前項(xiàng)目里面用到的遍歷數(shù)據(jù)的函數(shù)不是同一個(gè)呀(項(xiàng)目里面用到的函  數(shù):$.each(dataresource,function(index,element))),于是,就好好研究了下,果然在JS里面有兩個(gè)相似的函數(shù),于是也就有了今天的主題:

 1.$(selector).each(function(index,element))

 2.$.each(dataresource,function(index,element))

接下來就對(duì)這兩個(gè)函數(shù)做深入的探討:

1.$(selector).each(function(index,element))

作用:在dom處理上面用的較多

  <ul id="each_id">
    <li>muzi</li>
    <li>digbig</li>
    <li>muzidigbig</li>
  </ul>

js遍歷函數(shù):

  function traversalDOM(){
    $("#each_id li").each(function(){
       alert($(this).text())
    });
  }
  traversalDOM();

輸出結(jié)果:

2.$.each(dataresource,function(index,element))

作用:在數(shù)據(jù)處理上用的比較多

示例:

此處沒有html代碼,只有js代碼,如下:

  function traversalData(){
    var jsonResourceList = '[{"id":"1","tagName":"apple"},{"id":"2","tagName":"orange"},{"id":"3","tagName":"banana"},{"id":"4","tagName":"watermelon"}]';
    if(jsonResourceList.length >0){
      $.each(JSON.parse(jsonResourceList), function(index, currentObj) {
        alert(currentObj.tagName);
      });
    }
  }
  traversalData()

3.最終結(jié)論:

在遍歷DOM時(shí),通常用$(selector).each(function(index,element))函數(shù);

在遍歷數(shù)據(jù)時(shí),通常用$.each(dataresource,function(index,element))函數(shù)。

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接

相關(guān)文章

最新評(píng)論