Uncaught SyntaxError: missing)在循环参数列表后
Uncaught SyntaxError: missing ) after argument list in loop
我的代码在第21行中一直得到相同的错误。
if(typeof jQuery === undefined){
throw "jQuery is required for sapphire to work. Didn't you read the README?";
}
(function ( $ ) {
$.fn.slider = (function(options,images) {
var settings = $.extend({
slideCount: 4,
animationType:"none",
slideDuration:2000,
sliderSize:1100,
looptimes:300000000000000000000000000000000000000000
},options);
for(var i = 0; i<options.looptimes; i++){
var j = 0;
$("#sapphire-slide").append("<img src='"+images[j]+"'>");
setTimeout(function() {
if(j<options.slideCount-1)
j++;
}else if(j===options.slideCount-1){
j=0;
}
},options.slideDuration);
}
);
})( jQuery );
我不确定是什么导致这个错误,它看起来像完美的语法对我来说。谢谢!
在传递给setTimeout
的函数中为if
添加了一个额外的右括号:
if (j < options.slideCount - 1)
j++;
// the errant closing brace is on the next line:
}
else if(j === options.slideCount - 1)
{
j = 0;
}
或者,正如其他人提到的,在if
上添加一个开始大括号,以形成一个合适的块:
if (j < options.slideCount - 1)
{ // you need this opening brace
j++;
}
else if(j === options.slideCount - 1)
{
j = 0;
}
您缺少if
上的开头{
,并且您缺少最后第二行)
:
}
。(function ($) {
$.fn.slider = (function (options, images) {
var settings = $.extend({
slideCount: 4,
animationType: "none",
slideDuration: 2000,
sliderSize: 1100,
looptimes: 300000000000000000000000000000000000000000
}, options);
for (var i = 0; i < options.looptimes; i++) {
var j = 0;
$("#sapphire-slide").append("<img src='" + images[j] + "'>");
setTimeout(function () {
if (j < options.slideCount - 1) { // <--- add this {
j++;
} else if (j === options.slideCount - 1) {
j = 0;
}
}, options.slideDuration);
}
}); // <--- add a } on this line
})(jQuery);
请注意,修复这种事情只是计数括号和圆括号的问题,并确保它们是平衡的。
相关文章:
- Javascript:用while循环在给定的count参数中重复一个字符串
- JS for循环来设置HTML对象参数
- 在 Javascript 中循环使用参数的过滤器
- 循环jQueryajax和传递参数的正确方式
- jQuery使用最后一个参数在Javascript循环中单击绑定函数
- 循环遍历数组,并在javascript中向sql查询添加参数
- 如何动态使用for循环,将具有不同参数的函数推送到数组中
- .eq()参数在循环中不起作用
- 循环变量作为异步函数调用中的参数
- 如何避免在将索引作为函数的参数发送时引用for循环中的最后一个索引
- 在Javascript中修改循环函数的参数
- 如何跟踪有序列表中的顺序,该列表具有一个循环列表项,提供不同的参数
- jquery每个带有参数的循环调用函数
- 从嵌套循环 Javascript 中的一个循环访问参数
- 函数根据设置间隔循环,但参数不同
- 将 for 循环参数传递到每个语句中
- 在 PHP 循环中调用 js 函数,同时将 php 变量作为参数传递给其中一个函数
- JavaScript循环承诺在参数中使用数组进行迭代
- 在使用循环参数的字符填充数组时遇到麻烦
- Uncaught SyntaxError: missing)在循环参数列表后