意外的令牌对于数组来说是非法的

时间:2015-06-04 16:03:44

标签: jquery arrays token

我无法弄清楚为什么我从Chrome的开发者工具中收到错误。以下一行:

var accessoriesCats = [ “Beaded Accessories”, “Cufflinks”, “Flip Flops”, “Floral Accessories”, “Foot Jewelry”, “Hair Accessories”, “Hankies”, “Jewelry”, “Leg Garters”, “Purses”, “Shoe Stickers”, “Something Blue”, “Tiaras”, “Totes” ];

出现错误:

  

未捕获的SyntaxError:意外的标记ILLEGAL。

我不确定这条线确实是问题,还是别的什么。

以下是整个代码:

<script>
    if (window.location.href.indexOf("category-s/2022.htm") != -1) {
            var accessoriesCats = [ “Beaded Accessories”, “Cufflinks”, “Flip Flops”, “Floral Accessories”, “Foot Jewelry”, “Hair Accessories”, “Hankies”, “Jewelry”, “Leg Garters”, “Purses”, “Shoe Stickers”, “Something Blue”, “Tiaras”, “Totes” ];
                $('#content_area > table:nth-child(6) > tbody > tr > td > table:nth-child(1) > tbody > tr > td > table > tbody').find('a').each(accessoriesCats, function(){
                            $(this).append('<span class="promo__text”>”+accessoriesCats+”</span>');
                            $(this).removeClass('smalltext colors_text').addClass('subcatRollover');
            });
    }
</script>

2 个答案:

答案 0 :(得分:2)

您使用了错误引号,使用"'代替

var accessoriesCats = [ "Beaded Accessories", "Cufflinks", "Flip Flops", "Floral Accessories", "Foot Jewelry", "Hair Accessories", "Hankies", "Jewelry", "Leg Garters", "Purses", "Shoe Stickers", "Something Blue", "Tiaras", "Totes" ];

答案 1 :(得分:1)

它的引号,“”这些是不同的unicode版本,因此编译器无法识别它们。您需要""''

请改为尝试:

var accessoriesCats = [ 'Beaded Accessories', 'Cufflinks', 'Flip Flops', 'Floral Accessories', 'Foot Jewelry', 'Hair Accessories', 'Hankies', 'Jewelry', 'Leg Garters', 'Purses', 'Shoe Stickers', 'Something Blue', 'Tiaras', 'Totes' ];