zoukankan      html  css  js  c++  java
  • jQuery通用的全局遍历方法$.each()用法实例

    1.jQuery通用的全局遍历方法$.each()用法

    2. test.json文件代码:

    3. html代码

    4.jQuery代码

    <script src="jquery-1.3.1.js" type="text/javascript"></script>
    <script type="text/javascript">
    /*
    1.$.each()是jquery的一个通用的遍历方法,可用于遍历对象和数组
    2.$.each()函数不同于jquery对象的each()方法,它是一个全局函数,不操作jquery对象,而是以一个数组或者对象作为第一个参数,以一个回调函数作为第二个参数。
    回调函数拥有两个参数:第一个参数为对象的成员或数组的索引,第二个参数为对应变量或内容
    */ $(function(){ $('#send').click(function() { $.getJSON('test.json', function(data) { $('#resText').empty(); var html = ''; $.each( data , function(commentIndex, comment) { html += '<div class="comment"><h6>' + comment['username'] + ':</h6><p class="para">' + comment['content'] + '</p></div>'; }) $('#resText').html(html); }) }) }) </script>
  • 相关阅读:
    可持续化线段树(主席树)
    2016-06-19 NOIP模拟赛
    0618图的整理
    1536 海战
    1005 生日礼物
    3280 easyfinding
    2594 解药还是毒药
    2919 选择题
    1845 二叉查找树
    1174 靶形数独
  • 原文地址:https://www.cnblogs.com/yangzailu/p/7791976.html
Copyright © 2011-2022 走看看