为什么这段代码不起作用?我的视觉工作室代码告诉我" else"在 "否则如果"有声明或声明预期。 我的剧本:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
var a = 1+1;
var y = 1.5*2
if (a = 2){
for (var i = 0; i<5; i = i + 2){
document.write("Hello "+ i +" Everyone.</br>")
} else if (y=3){
for (var j = 2; j < 10; j = j+3){
document.write("Hey there.")
}
}
}
</script>
</body>
</html>
答案 0 :(得分:7)
由于以下几个原因,您的代码无效:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
var a = 1+1;
var y = 1.5*2
if (a === 2) {
for (var i = 0; i<5; i = i + 2) {
document.write("Hello "+ i +" Everyone.</br>")
}
} else if (y === 3) {
for (var j = 2; j < 10; j = j+3){
document.write("Hey there.")
}
}
</script>
</body>
</html>