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
?