出现错误然后尝试在警报 window 中显示一些文本以及数组值
Getting an error then tryiing to display some text in alert window together with array values
我正在尝试制作警报脚本来显示一些数组值和一些文本。
带有 alert(numbers[i] + " is" + student[i] );
的代码工作正常,但如果我在 numbers[i]
之前添加一些文本,它不起作用我尝试了单引号和双引号,但没有成功。
<button onclick="students()">Try now</button>
<script>
function students() {
var student = ["Maria", "Jane", "Sue", "Mary", "Amber"];
var numbers = ["first", "second", "third", "fourth", "fifth"];
for (var i = 0; i < student.length; i++) {
alert(numbers[i] + " is" + student[i]);
}
}
</script>
这行不通:
alert("In the student list" numbers[i] + " is" + student[i] );
只需先创建有效字符串,您就会看到缺少“+”:
var message = "In the student list " + numbers[i] + " is" + student[i];
alert(message)
我正在尝试制作警报脚本来显示一些数组值和一些文本。
带有 alert(numbers[i] + " is" + student[i] );
的代码工作正常,但如果我在 numbers[i]
之前添加一些文本,它不起作用我尝试了单引号和双引号,但没有成功。
<button onclick="students()">Try now</button>
<script>
function students() {
var student = ["Maria", "Jane", "Sue", "Mary", "Amber"];
var numbers = ["first", "second", "third", "fourth", "fifth"];
for (var i = 0; i < student.length; i++) {
alert(numbers[i] + " is" + student[i]);
}
}
</script>
这行不通:
alert("In the student list" numbers[i] + " is" + student[i] );
只需先创建有效字符串,您就会看到缺少“+”:
var message = "In the student list " + numbers[i] + " is" + student[i];
alert(message)