zoukankan      html  css  js  c++  java
  • jquery--遍历

    1、遍历元素下所有子元素  (不包括孙子级)

    $("#taskPropertyForm").children().each(function (i, item) {
                    var $this = $(item);
                    var _this = item;
                    console.log(i);
                    console.log(item.tagName);
                });

    2、遍历元素下所有的子元素(包括所有子级,孙子及。。。)

    $("#taskPropertyForm").find("*").each(function (i, item) {
                    var $this = $(item);
                    var _this = item;
                    console.log(i);
                    console.log(item.tagName);
                });

    3、es6

    var obj=arr.find(function (obj) {
        return obj.id === 3
    })
    array.forEach(function(v){  
        console.log(v);  
    });
    Array.forEach(function(value , index , array){ //value为遍历的当前元素,index为当前索引,array为正在操作的数组
      //do something
    },thisArg)      //thisArg为执行回调时的this值

    3、遍历对象

    var b = new Object;
                b.property = [{
                    "id": "f_p_id",
                    "text": "span",
                    "value": "1111"
                }, {
                    "id": "f_p_name",
                    "text": "input",
                    "value": "222222"
                }, {
                    "id": "f_p_info",
                    "text": "textarea",
                    "value": "333333"
                }];
    
                $.each(b.property, function (i, item) {
                    console.log(item);
                });

    // b.property.forEach(function () {
                //     console.log($(this).id);
                // });
     

    4、js遍历对象

    var objn = {};
    
            objn.nodes = {};
    
    
            for (i in obj.nodes) {
                // console.log(obj.nodes[i]);
                var nodes = {};
    
                objn.nodes[obj.nodes[i].id] = {
                    "name": obj.nodes[i].name,
                    "id": obj.nodes[i].id
                }
            }

     5、

    $(".J_menuTab.active")
     
    class="J_menuTab active"
  • 相关阅读:
    android 入门-ID
    Win10 VS2015 社区版切换到VS2013社区版 进行维护之前的项目
    Win10 AppBar
    Win10 保存Element到相册
    LRUCache c#
    Winform解决界面重绘闪烁的问题
    使用Emit实现给实体赋值
    Winform 自定义窗体皮肤组件
    WPF 分享一种背景动画效果
    使用MEF与Castle实现AOP
  • 原文地址:https://www.cnblogs.com/jentary/p/11942877.html
Copyright © 2011-2022 走看看