zoukankan      html  css  js  c++  java
  • 代码:遍历

    遍历obj对象:  2016-5-20

    var obj={
        a:1,
        b:2,
        c:3
    }
    for(var item in obj){
        console.log(item);
    }

     

    $.each 遍历数据:  2016-5-25

    var data={
        a:1,
        b:2,
        c:3,
        d:4,
        e:5
    }
    $.each(data,function(key,val){
        console.log(key+'-------'+val);
    });

    $('ul li').each() 遍历DOM对象:  2016-5-25

    //遍历
    $("ul li").each(function(){
        console.log($(this).text())
    });
    $("ul li").each(function(i,element){
        console.log($(this).text())
        console.log($(element).text());
        console.log(i);
    });

    遍历表单文本框:

    <script type="text/javascript" src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
    <script type="text/javascript">
    $(function(){
        $("#button").click(function(){
            //遍历表单文本框
            $("#form1 input[name]").each(function(){
                $(this).bind("blur",function(){
                    testtest($(this));
                });//注意blur事件写法!
                
                function testtest(_this) {
                    console.log(_this.val());
                }
            })
        });
    });
    </script>
    <form method="post" action="" id="form1">
    <input type="text" name="a1" value="a111"><br>
    <input type="text" name="a2" value="a222"><br>
    <input type="text" name="a3" value="a333"><br>
    <input type="text" name="a4" value="a444"><br>
    <input type="button" value="button" id="button">
    </form>

    ...

  • 相关阅读:
    Best Time to Buy and Sell Stock II
    Subsets II
    Subsets I
    Combinations
    Permutation Sequence
    Next Permutation
    Anagrams
    Combination-Sum II
    Combination-Sum I
    Permutations II
  • 原文地址:https://www.cnblogs.com/qq21270/p/5512976.html
Copyright © 2011-2022 走看看