jQuery脚本无法在Internet Explorer中运行(第1行char 1上的语法错误)

Zip*_*ive 7 html javascript jquery internet-explorer syntax-error

我正在为一个新项目开发一个响应式html模型,它包含一些jquery脚本,可以在每个浏览器上运行完美...除了Internet Explorer(我目前正在IE9上测试它).

我自然检查了IE的javascript控制台,它给出了以下错误消息:

SCRIPT1002: Syntax error 
scripts.js, line 1 character 1
Run Code Online (Sandbox Code Playgroud)

我完全不知道它可能来自哪里,因为DreamWeaver或Komodo Edit都没有发现任何错误.

该模型在以下地址在线:http://zipion-live.be/cal-bw/

这是导致错误的脚本:

const visible = "visible";
const hidden = "hidden";
const open = "open";

$(document).ready(function(e) {
    $(".collapsible_container .links").hide();
    showHomeMenu();

    $("#home_link").click(showHomeMenu);

    $("#admin_link").click(showAdminMenu);

    $("#left_menu .links a").click(function() {
        $("#left_menu .links").slideUp("fast");
        $("#left_menu .collapsible_container").removeClass(open);
    });

    $("section .section_header").click(function() {
        var sectionContent = $(this).parent("section").children(".section_content");
        var sectionHeader = $(this);
        toggleSection(sectionHeader, sectionContent);
    });
});

function toggleSection(sectionHeader, sectionContent) {
    var isOpen = sectionHeader.hasClass(open);

    if (isOpen) {
        sectionContent.slideUp("slow", function() {
            sectionHeader.removeClass(open);
        });
    } else {
        sectionContent.slideDown("slow");
        sectionHeader.addClass(open);
    }
}

function setLeftMenuHeight() {
    var visibleChildren = $("#left_menu .collapsible").not(".hidden")

    if (visibleChildren.length > 8) {
        $("aside").removeClass("h100").addClass("h150");
    } else if (visibleChildren.length > 4) {
        $("aside").removeClass("h150").addClass("h100");
    } else {
        $("aside").removeClass("h100").removeClass("h150");
    }
}

function showHomeMenu() {
    $("#left_menu .admin").addClass("hidden");
    $("#left_menu .home").removeClass("hidden");
    $("#left_menu .admin h3 a").unbind("click");
    setLeftMenuHeight();

    $("#left_menu .home h3 a").click(function() {
        var current = $(this).parent("h3").parent(".collapsible_container").children(".links")
        animateMenu(current);
    });
}

function showAdminMenu() {
    $("#left_menu .home").addClass("hidden");
    $("#left_menu .admin").removeClass("hidden");
    $("#left_menu .home h3 a").unbind("click");
    setLeftMenuHeight();

    $("#left_menu .admin h3 a").click(function() {
        var current = $(this).parent("h3").parent(".collapsible_container").children(".links")
        animateMenu(current);
    });
}

function animateMenu(current) {
    var isVisible = current.hasClass(visible)       

    $("#left_menu .links").removeClass(visible);
    $("#left_menu .collapsible_container").removeClass(open);

    $.when($("#left_menu .links").slideUp("fast")).then(function() {
        if (!isVisible) {
            current.slideDown("fast");
            current.addClass(visible);
            current.parent(".collapsible_container").addClass(open);
        } else {
            current.parent(".collapsible_container").removeClass(open);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

对这个问题有什么看法吗?我对jQuery很新,我在这里完全无能为力......

PS:我在版本1.11.0中使用jquery,以防相关.

Alv*_*aro 7

虽然const 是Javascript 1.5标准功能,但现代版IE(6-10)不支持它.只有基于gecko的浏览器和Chrome支持它.

如今在javascript使用的变量var,不是const为了避免这个问题.

改变这个:

const visible = "visible";
const hidden = "hidden";
const open = "open";
Run Code Online (Sandbox Code Playgroud)

对此:

var visible = "visible";
var hidden = "hidden";
var open = "open";
Run Code Online (Sandbox Code Playgroud)

  • `const`是一个新功能,IE尚未支持. (4认同)
  • 它在IE11中得到支持 (3认同)