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"
  • 相关阅读:
    接口缓存--把接口放在redis数据库中,减少访问量
    使用vue和drf后台进行登录页面和注册页面(本文大概的疏通一下前后台是怎么交互的)
    vue导入css,js和放置html代码
    存储过程
    触发器
    视图
    pymysql模块使用
    权限管理
    多表数据查询
    单表数据查询
  • 原文地址:https://www.cnblogs.com/jentary/p/11942877.html
Copyright © 2011-2022 走看看