繁体   English   中英

Javascript 无法在 Internet Explorer 11 上运行

[英]Javascript failing to work on the internet explorer 11

此代码仅出现在 Internet Explorer 版本:IE11 上,我遇到了一些问题。 这是解释的简短版本。 得到代码控制台错误:原始消息 SCRIPT1002:语法错误:和指向:=> 值的链接。

// Bind click events to toggle buttons and pass in slide flip value
                                next.addEventListener('click', () => {
                                    pushSlide(1);
                                });
                                prev.addEventListener('click', () => {
                                    pushSlide(-1);
                                });

我可以在这里提供更多信息。 http://scorpion3d.com/index.html#fotografija

此链接将引导您解决问题。 好的,下面是完整代码,如果您将在其他浏览器上尝试它,它工作得很好。 图像正在显示,控制台上没有问题等。但在 Internet Explorer 上我看不到任何图像按钮工作,我不知道如何修复它。 完整的Java脚本如下:

// Flickr configurations
// Obfuscated API key var for demo
const _0x6e6e=["\x65\x66\x63\x38\x33\x64\x63\x63\x64\x37\x63\x31\x64\x30\x61\x65\x39\x33\x66\x34\x61\x61\x37\x61\x66\x62\x39\x37\x31\x66\x63\x65"];const apiKey=_0x6e6e[0]
// To personalize app, replace with your own API key
// const apiKey = '';
const album = '72157688964206172',
    albumOwner = '154845055@N05',
    flickrUrl = 'https://api.flickr.com/services/rest/',
    method = '?method=flickr.photosets.getPhotos&api_key=',
    perPage = '100',
    formatCallback = '&format=json&nojsoncallback=1',
    contentContainer = document.getElementById('carouselContent'),
    oReq = new XMLHttpRequest();
// Handle a response from the Flickr API
function reqListener () {
    const flickrPhotos = JSON.parse(this.responseText);
    console.log(flickrPhotos.photoset);
    // Parse response for album and owner information
    const ownerName = flickrPhotos.photoset.ownername,
        albumTitle = flickrPhotos.photoset.title,
        albumUrl = 'https://www.flickr.com/photos/' + albumOwner + '/albums/' + album,
        albumOwnerUrl = 'https://www.flickr.com/photos/' + albumOwner;
    // append response data to HTML DOM elements
    albumInfo.innerHTML = albumTitle;
    owner.innerHTML = ownerName;
    albumLink.href = albumUrl;
    albumOwnerLink.href = albumOwnerUrl;
    // Iterate through flickrPhotos in the response
    flickrPhotos.photoset.photo.forEach(function(foto) {
        // Generate the URL for individual photo based on template
        const url = 'https://farm' + foto.farm + '.staticflickr.com/' + foto.server + '/' + foto.id + '_' + foto.secret + '.jpg';
        const photoTitle = foto.title;
        // Generate the necessary slide markup
        //   <span data-function="slide">
        //       <p>title</p>
        //       <img src="" />
        //   </span>
        const span = document.createElement('span'),
            img = document.createElement('img'),
            title = document.createElement('p');
        // append response data to generated HTML DOM elements
        img.src = url;
        img.alt = photoTitle;
        title.innerHTML = photoTitle;
        span.dataset.function = 'slide';
        span.appendChild(title);
        span.appendChild(img);
        // Now append the new slide to the slide container
        contentContainer.appendChild(span);
    });
    // Remote API request has been made and processed, initialize the carousel.
    flickrCarousel();
}
// API call to Flickr
oReq.addEventListener("load", reqListener);
oReq.open("GET", flickrUrl + method + apiKey + '&photoset_id=' + album + '&user_id=' + albumOwner + '&per_page=' + perPage + formatCallback);
oReq.send();
// Carousel function
function flickrCarousel () {
    // set scoped variables
    const carouselBox = document.getElementById('carouselBox'),
        prev = carouselBox.querySelector('.prev'),
        next = carouselBox.querySelector('.next'),
        slides = carouselBox.querySelectorAll('[data-function=slide]'),
        deck = slides.length;
    let slide = 0,
        currentSlide = slides[0];
    // Find current slide of array and add selector
    currentSlide.classList.add('current-slide');
    // slider function
    function pushSlide(flip) {
        // Use value of array to find node and remove selector
        currentSlide.classList.remove('current-slide');
        // Using value of current slide, add flip value to determine next slide value
        slide = slide + flip;
        // allows for full rotation of carousel; if 0 set value to -1 of array length
        if (flip === -1 && slide < 0) {
            slide = deck - 1;
        }
        // allows for full rotation of carousel; if max length of array, set to 0
        if (flip === 1 && !slides[slide]) {
            slide = 0;
        }
        // determine active slide and add selector
        currentSlide = slides[slide];
        currentSlide.classList.add('current-slide');
    }
    alert('11111111111111111111111111');
    // Bind click events to toggle buttons and pass in slide flip value
    next.addEventListener('click', () => {
        pushSlide(1);
    });
    prev.addEventListener('click', () => {
        pushSlide(-1);
    });
    // Bind keyboard events to slide triggers
    document.addEventListener('keydown', event => {
        if( event.keyCode == 39 ) {
            pushSlide(1);
        }
        if( event.keyCode == 37 ) {
            pushSlide(-1);
        }
    });
};

提前感谢您的时间。

您的代码是用 ES6 语法编写的,E11 似乎不支持这种 JavaScript 语法。 您将需要删除所有const s 和let s 和=> s。 如果您手动执行此操作,您可能需要删除更多内容。

这可以通过使用转译器来自动化。 我最喜欢的是巴别塔

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM