Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 循环中参数列表后未捕获的语法错误(缺少)_Javascript - Fatal编程技术网

Javascript 循环中参数列表后未捕获的语法错误(缺少)

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:

我在第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 );
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);