Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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 这是有效的数组(值)吗?_Javascript_Jquery - Fatal编程技术网

Javascript 这是有效的数组(值)吗?

Javascript 这是有效的数组(值)吗?,javascript,jquery,Javascript,Jquery,你能像我一样把ID作为数组值吗?因为这目前对我不起作用。Bo,#foo不是有效的JavaScript表达式。你的意思是“#foo” 此外,您还可以(应该)使用数组文字而不是新数组: var leaguetable = new Array(); leaguetable[0]= #leaguetable; leaguetable[1]= #leaguetable1; leaguetable[2]= #leaguetable2; leaguetable[3]= #leaguetable3; l

你能像我一样把ID作为数组值吗?因为这目前对我不起作用。

Bo,
#foo
不是有效的JavaScript表达式。你的意思是
“#foo”

此外,您还可以(应该)使用数组文字而不是新数组:

var leaguetable = new Array(); 

leaguetable[0]= #leaguetable; 
leaguetable[1]= #leaguetable1;
leaguetable[2]= #leaguetable2; 
leaguetable[3]= #leaguetable3;
leaguetable[4]= #leaguetable4; 
leaguetable[5]= #leaguetable5; 
leaguetable[6]= #leaguetable6; 
leaguetable[7]= #leaguetable7; 
leaguetable[8]= #leaguetable8;

您需要将您的值括在引号
“#leaguetable1”、“#leaguetable2”

但是,您可以使用一个简单的
for
循环来自动实现它,而不是手动添加它:

var leaguetable = [
    '#leaguetable',
    '#leaguetable7',
    ...
    '#leaguetable8'
];
var leaguetable=newarray();
联盟表[0]=“联盟表”;

对于(var i=1;我用单引号将它们作为string
leaguetable[0]='#leaguetable'
或使用leaguetable.push('#leaguetable');leaguetable.push('#leaguetable 1');等等。我能问一下吗,因为我从来都不懂它。.“foo”是什么意思表示?它只是您使用的东西还是特定的东西?@DuploW它是示例代码中变量的任意名称或值。可以是任何东西(只要它是有效标识符);我自己编写一次性代码时经常使用
test
。@AnthonyGrist啊,这就是我一直在想的,现在可以更容易地理解示例代码了。谢谢:P@ThiefMaster为什么使用文字数组更好?我发现我的方法在更改内容时更容易检查。你能想象你的方法会是什么样的更改吗更简洁易懂?谢谢,你能解释一下代码的作用吗?想想这一部分:为了(var i=1;i@DuploW它只是将i从
1
增加到
8
,并附加到
#leaguetable
8倍,所以
#leaguetable 1
#leaguetable 2
#leaguetable 3
…我还建议您学习一个关于javascript的基本教程,可以通过互联网在Goo上搜索格洛。
var leaguetable = new Array(); 

leaguetable[0]= '#leaguetable';
for(var i=1; i<=8; i++) {
    leaguetable[i] = '#leaguetable' + i;
}

console.log(leaguetable);