美文网首页
js行内变量传参,函数内部实参调用

js行内变量传参,函数内部实参调用

作者: Volon | 来源:发表于2019-06-20 17:34 被阅读0次
    
    <!DOCTYPE html>
    <html>
    
        <head>
            <meta charset="utf-8" />
            <title></title>
        </head>
    
        <body>
            <button onclick="ddd(this.name)" name="people">11111111111111111</button>
            <script type="text/javascript" src="js/jquery.js"></script>
            <script>
                var aa;
    
                function getData() {
                    $.ajax({
                        type: "get",
                        url: "test.json",
                        dataType: "json",
                        async: false,
                        success: function(data) {
                            aa = data;
                        }
                    });
                    return aa;
                }
                var b = getData();
                       console.log(b)
                function ddd(obj) {
                    $.each(b, function(k, v) {
                        if(k == obj) {
                            for(var i in v){
                                console.log(v[i].name)
                            }
                        }
                    });
                }
            </script>
        </body>
    
    </html>
    
    
    test.json:
    {
    "people":[
    {"name":"张三",
    "age":"3"},
    {"name":"里斯",
    "age":"4"}
    ],
    "employees": [
    { "firstName":"Bill" , "lastName":"Gates" },
    { "firstName":"George" , "lastName":"Bush" },
    { "firstName":"Thomas" , "lastName":"Carter" }
    ]
    }
    
    
    

    相关文章

      网友评论

          本文标题:js行内变量传参,函数内部实参调用

          本文链接:https://www.haomeiwen.com/subject/maijqctx.html