Javascript 循环中参数列表后未捕获的语法错误(缺少)
我在第21行的代码中不断出现相同的错误Javascript 循环中参数列表后未捕获的语法错误(缺少),javascript,Javascript,我在第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:
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 );
if(typeof jQuery==未定义){
抛出“sapphire需要jQuery才能工作。您没有阅读自述吗?”;
}
(函数($){
$.fn.slider=(函数(选项、图像){
变量设置=$.extend({
幻灯片计数:4,
animationType:“无”,
教育:2000年,
幻灯片大小:1100,
循环次数:3000000000000000000000000
},选项);
对于(var i=0;i您在传递给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
上的开头{
,缺少前面最后一行的结尾}
:
(函数($){
$.fn.slider=(函数(选项、图像){
变量设置=$.extend({
幻灯片计数:4,
animationType:“无”,
教育:2000年,
幻灯片大小:1100,
循环次数:3000000000000000000000000
},选项);
对于(var i=0;i 如果(j循环时间的长整数会很好。我相信在座的其他人都在告诉自己,这是一个非常糟糕的问题。我们不是来帮助设置代码格式/缺少大括号的。请使用某种IDE来实现这一点。IDE中、浏览器中和在线上都有代码筛选工具,您可以使用使用它将准确地告诉您问题所在。Sytnax错误不应该是这里的问题,这是错误的:typeof jQuery===undefined
。它永远不会是true
。这是一个非常常见的错误,也是在仅测试undefined
时不使用typeof
的原因之一。只需使用window.jQue即可ry===未定义
。或者更确切地说,缺少大括号。
if (j < options.slideCount - 1)
{ // you need this opening brace
j++;
}
else if(j === options.slideCount - 1)
{
j = 0;
}
(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);