如果IE11中的密钥输入错误 - 意外标识符,字符串或数字

时间:2018-04-20 18:43:06

标签: javascript jquery object

我已经测试了这段代码,它在所有版本的Edge,Firefox和Chrome中都运行良好,但在IE11或更早版本中无效。我希望找到我的问题或创建更适合旧版浏览器的版本。我有一些拒绝升级的客户不要问大声笑。

收到错误:意外的标识符,字符串或数字

google上唯一可以找到的是它引用了尾随逗号,但我在下面的代码中没有任何内容。我评论了那些破碎的部分。

// Slideshow System
var s =  Foundation.MediaQuery.get('medium').match(/\(([^)]+)\)/)[1].replace('em','').split(' ');
var small = (s[(s.length-1)]*16);
var m = Foundation.MediaQuery.get('large').match(/\(([^)]+)\)/)[1].replace('em','').split(' ');
var medium = (m[(m.length-1)]*16);
$('.omada-ss').each(function(){
    var x  = $(this); 
    if(x.attr("id") !== undefined){ var id = x.attr('id'); }else{
        var id = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        for (var i = 0; i < 5; i++){ id += possible.charAt(Math.floor(Math.random() * possible.length));}           
        x.attr('id',id);
    }
    if (!x.hasClass("swiper-container")){ x.addClass('swiper-container'); }
    if(x.find('div.swiper-wrapper').length == 0){ x.wrapInner('<div class="swiper-wrapper"></div>'); }
    x.find('.swiper-wrapper>div').each(function(){ if(!$(this).hasClass("swiper-slide")){ $(this).addClass('swiper-slide');} });
    if(x.hasClass('has-text')){ x.find('.spiper-slide').each(function(){ $(this).wrapInner('<div class="swiper-text"></div>'); }); }
    if(x.data("options") !== undefined){ var options = film = x.data("options"); }
    else{ var options = film = {autoplay: { delay: 2500, disableOnInteraction: true } } }
    /*
    if('breakpoints' in options){ options.breakpoints = { [medium] :options.breakpoints.medium, [small] : options.breakpoints.small }; }
    if('spaceBetween' in options){ options.spaceBetween = parseInt(options.spaceBetween); }
    if('pagination' in options){ x.append('<div class="swiper-pagination"></div>'); }
    if('navigation' in options) { x.append('<div class="swiper-button-next"></div><div class="swiper-button-prev"></div>'); }
    if('speed' in options){ options.speed=film.speed=parseInt(options.speed); }
    */
    var swiper = new Swiper('#'+id,options);
    if('filmstrip' in film){
        delete film.navigation;
        delete film.pagination;
        /*
        if('breakpointsbs' in film){
            film.breakpoints={ [medium] :film.breakpointsbs.medium, [small] : film.breakpointsbs.small };
            film.slidesPerView = parseInt(film.breakpointsbs.large.slidesPerView);
            film.centeredSlides=true;
            delete film.breakpointsbs;
        }
        */
        film.touchRatio=0.2;
        film.slideToClickedSlide=true;  
        var thumbs = new Swiper('#'+id+'-filmstrip', film);
        swiper.controller.control = thumbs;
        thumbs.controller.control = swiper;
    }
    if('pauseonhover' in options){ x.hover(function(){swiper.autoplay.stop();},function(){swiper.autoplay.start();}); }
}); 

以下是附加了类和选项的示例div

<div id="UBMoSlzKfT" class="swiper-container omada-ss" data-options='{"pauseonhover":true,"autoplay":{"delay":"5000","disableOnInteraction":false},"loop":true,"speed":"2000","navigation":{"nextEl":".swiper-button-next","prevEl":".swiper-button-prev"},"keyboard":{"enabled":true}}'>
    <div>Slide 1</div>
    <div>Slide 2</div>
    <div>Slide 3</div>
</div>

1 个答案:

答案 0 :(得分:4)

问题是你正在使用&#34;计算属性&#34; film.breakpoints对象中Object Initializer SpecNOT supported in IE11 documentation。 IE11将无法动态解析[medium][small]等对象属性键。如果您计划支持IE11或使用Babel等工具来转换该功能,则需要替换它。

您可以尝试使用括号表示法的行与您的&#34;动态&#34;结合使用。变量来相应地设置值。在下面的示例中,[small][medium]film.breakpoints对象上设置属性之前进行评估:

film.breakpoints[medium] = film.breakpointsbs.medium;
film.breakpoints[small] = film.breakpointsbs.small;

&#13;
&#13;
var small = 600;

var film = {
  breakpoints: {
    1024: {
      "name": "desktop"
    },
    768: {
      "name": "tablet"
    }
  }
};

film.breakpoints[small] = { name: 'phablet' };

console.log(film.breakpoints);
&#13;
&#13;
&#13;

希望这有帮助!