[英]Missing a ; after a for loop: Error found in JS Lint and with appendChild
我正在尝试删除一个appendChild并不断收到错误-
语法错误:丢失; 在for循环初始化器之后
我以前从未见过此错误。 这是我的代码。
这里缺少什么?
var allChildren = document.getElementById("box").children;
var moving = document.getElementById("box2");
var newLocation = parseInt(moving.style.top, 0);
var newLocation2 = parseInt(moving.style.left, 0);
for (imageCheer); {
if (newLocation2 = moving.style.left && newLocation = moving.style.top)
{
return x;
allChildren.removeChild(list.childNodes[0]);
}
for (imageMarsh); {
if (newLocation2 = moving.style.left && newLocation = moving.style.top)
{
return x;
allChildren.removeChild(list.childNodes[0]);
}
}
您的for循环在语法上是不正确的。 通常,它们具有for (init; condition; step)
。 for (var i = 0; i< 10; i++)
EG。 您的循环缺少条件和步骤。
您还应该在for();
之后删除分号for();
因为否则循环体将不会执行。
而且循环体也是错误的。 您想用return x
实现什么? 考虑如果在函数内部使用return,它将立即停止函数的执行,其余语句将不执行。
还应考虑在JavaScript中使用==
甚至更好的===
进行相等性检查。 单个=
是分配。
而且,最后您缺少一些用于循环主体的右括号。
我认为for (var i in imageCheer) {..}
可以工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.