我有一个奇怪的语法问题。我收到以下错误:
未捕获到的SyntaxError:其他意外令牌
与该问题有关的代码:
if (j <= 9) {
nameUs[i].className += ' selected-country';
pointUs[i].className += ' selected-country';
for (k = 1; k < imageTime.length+1; ++k) {
$('#avatar-'+[j]+' .img-car-'+[k]+'').attr('href','cars/car-'+[k]+'.png');
$('#backgrounds .background-'+[j]).show();
pushPercent.push(percentHere);
if (j == 1) {
$('.'+$.cookie('original-class')).addClass('selected');
$('.'+pinnedIncentive).addClass('selected');
if (pinnedIncentive == 'kpis' ) {
$('.mm-flag .flag-text').html('300€');
$('.mm-flag .flag-text').css('font-size','72px');
$('.mm-flag .flag-text').css('line-height','60px');
}
}
if (j == 9) {
nameUs[i].className += ' last-one';
}
} else if (j > 9 && j <= 19) {
nameUs[i].className += ' selected-country right-sided last-one';
pointUs[i].className += ' selected-country right-sided last-one';
$(pointUs[i]).css('padding-top',233*([j]-10)+'px');
$(nameUs[i]).css('padding-top',233*([j]-10)+'px');
$('#backgrounds-right .background-'+[j]).show();
if (j == 9) {
nameUs[i].className += ' last-one';
}
}
j++;
}
有人可以给我一个解决方法的线索吗?这是我第一次遇到这个奇怪的错误。预先感谢!
答案 0 :(得分:2)
从您发布的Pastebin链接中,您忘了在此处关闭for
循环:
if (j <= 9) {
nameUs[i].className += ' selected-country';
pointUs[i].className += ' selected-country';
for (k = 1; k < imageTime.length+1; ++k) { <---
$('#avatar-'+[j]+' .img-car-'+[k]+'').attr('href','cars/car-'+[k]+'.png');
****HERE******
$('#backgrounds .background-'+[j]).show();
答案 1 :(得分:0)
更正您的缩进时,我发现else if
附加在您的for循环中:
for (k = 1; k < imageTime.length+1; ++k) {
$('#avatar-'+[j]+' .img-car-'+[k]+'').attr('href','cars/car-'+[k]+'.png');
$('#backgrounds .background-'+[j]).show();
pushPercent.push(percentHere);
if (j == 1) {
$('.'+$.cookie('original-class')).addClass('selected');
$('.'+pinnedIncentive).addClass('selected');
if (pinnedIncentive == 'kpis' ) {
$('.mm-flag .flag-text').html('300€');
$('.mm-flag .flag-text').css('font-size','72px');
$('.mm-flag .flag-text').css('line-height','60px');
}
}
if (j == 9) {
nameUs[i].className += ' last-one';
}
} else if (j > 9 && j <= 19) {
在此处修复for循环:
for (k = 1; k < imageTime.length+1; ++k) {
$('#avatar-'+[j]+' .img-car-'+[k]+'').attr('href','cars/car-'+[k]+'.png');
}
并在此处修复else if
:
if (j == 9) {
nameUs[i].className += ' last-one';
} else if (j > 9 && j <= 19) {