webkit中的意外标记ILLEGAL

// if the box is outside the window, move it to the end
function checkEdge() {
    var windowsLeftEdge = $('#window').position().left;

    $('.box').each( function(i, box) {
        // right edge of the sliding box
        var boxRightEdge = $(box).position().left + $(box).width();

        // position of last box + width + 10px
        var newPosition = getNewPosition();

        if ( parseFloat(boxRightEdge) < parseFloat(windowsLeftEdge) ) { 
            $(box).css('left', newPosition);
            $(box).remove().appendTo('#window');
            first = $('.box:first').attr('class');
        }
    });
}​ //Uncaught SyntaxError: Unexpected token ILLEGAL Occurs Here

// arrange the boxes to be aligned in a row
function arrangeBoxes() {
    $('.box').each( function(i, item) {
        var position = $('#window').position().left + i * ( $(item).width());
        $(item).css('left', position+'px')
    });
}

// shifts all the boxes to the left, then checks if any left the window
function shiftLeft() {
    $('.box').animate({'left' : "-=100px"}, 5000, 'linear', checkEdge());
}

// returns the new location for the box that exited the window
function getNewPosition() {
    return $('.box:last').position().left + $('.box:last').outerWidth();
}

$(window).load(function() {
      arrangeBoxes();
    shiftLeft();
    setInterval('shiftLeft()', 5000);

    $('#gallery-slideshow').nivoSlider({
        effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
        slices:15,
        animSpeed:500, //Slide transition speed
        pauseTime:3000,
        startSlide:0, //Set starting Slide (0 index)
        directionNav:true, //Next & Prev
        directionNavHide:true, //Only show on hover
        controlNav:false, //1,2,3...
        keyboardNav:false, //Use left & right arrows
        pauseOnHover:false, //Stop animation while hovering
        manualAdvance:false, //Force manual transitions
        captionOpacity:0, //Universal caption opacity
        beforeChange: function(){},
        afterChange: function(){},
        slideshowEnd: function(){}, //Triggers after all slides have been shown
        lastSlide: function(){}, //Triggers when last slide is shown
        afterLoad: function(){} //Triggers when slider has loaded
    });

});

$(document).ready(function(){

    $('.class-table tr').click(function(){
        window.location=$(this).find("a").attr("href"); return false;
    });

    $('.special-workshop').click(function(){
        window.location=$(this).find("a").attr("href"); return false;
    });

});

我得到一个未捕获的SyntaxError:上面提到的线上的意外的令牌ILLEGAL。 它仅在Google Chrome和Safari中出现。 它在Firefox中工作,并且相同的代码适用于此JSBin(http://jsbin.com/uceqi/18)

到底是怎么回事?

在Stackoverflow上有大量的这个问题的引用,但他们似乎都不适用于这种情况。

如果有帮助,JSLint也会在该行字符2上抛出错误并且出现错误:“第22行字符2:意外的问题”。


删除该区域周围的所有不可见字符(空格),然后再次尝试。

在复制/粘贴代码时,我在Safari中看到了这个错误。 你可以选择一些无效的(但不可见的)字符。

当从jsFiddle复制时,曾经发生过很多事情。


它不适用于这个特定的代码示例,但作为谷歌的食物,因为我得到了同样的错误信息:

<script>document.write('<script src="…"></script>');</script>

会给这个错误,但

<script>document.write('<script src="…"><'+'/script>');</script>

将不会。

此处进一步说明:为什么在使用document.write()写入时为它分割<script>标记?


当脚本文件包含容器中的一些特殊字符以及当我在本地moode中运行(直接从本地磁盘运行)时,我得到了同样的错误。 我的情况是解决方案是明确地告诉编码:

<script src="my.js" charset="UTF-8"></script>
链接地址: http://www.djcxy.com/p/45975.html

上一篇: Unexpected token ILLEGAL in webkit

下一篇: Chrome: Uncaught SyntaxError: Unexpected end of input