Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 基本java脚本作用域_Javascript_Jquery - Fatal编程技术网

Javascript 基本java脚本作用域

Javascript 基本java脚本作用域,javascript,jquery,Javascript,Jquery,我在这段代码中得到一个错误: $(document).ready(function () { var appContainer = { apps: new Array() }; $("funcList div").each({ appContainer.apps.push("testing"); // this does not work, why? }) appContainer.apps.push("testin

我在这段代码中得到一个错误:

$(document).ready(function () {


    var appContainer = {
        apps: new Array()
    };


    $("funcList div").each({
       appContainer.apps.push("testing"); // this does not work, why?
    })

    appContainer.apps.push("testing");
    )


});
appContainer是否超出了each方法的范围? 这是我得到的错误:


感谢此处存在以下多个语法错误,您还需要查看选择器
funcList div
funcList
是ID还是类,如果是,请使用适当的选择器

$(document).ready(function () {
    var appContainer = {
        apps: new Array()
    };

    //need to pass a function as the argument here
    $("funcList div").each(function () {
        appContainer.apps.push("testing"); // this does not work, why?
    })

    //extra ) here
    appContainer.apps.push("testing");

    console.log(appContainer)
});
演示:

$(文档).ready(函数(){
var appContainer={
应用程序:新阵列()
};
//这里需要传递一个函数作为参数
$(“funcList div”)。每个(函数(){
appContainer.apps.push(“测试”);//这不起作用,为什么?
})
//(额外)这里
appContainer.apps.push(“测试”);
console.log(appContainer)
});

与您的问题没有直接关系,但是
funcList
不会匹配太多(除非您有一些奇怪的自定义元素)。你是说
.funcList
还是
#funcList