我正在为一个新项目开发响应式 html 模型,它包含一些可以在所有浏览器上完美运行的 jquery 脚本...除了 Internet Explorer(我目前正在 IE9 上测试它)。
我自然而然地检查了 IE 的 javascript 控制台,它给了我以下错误消息:
SCRIPT1002: Syntax error
scripts.js, line 1 character 1
我完全不知道这是从哪里来的,因为 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);
}
});
}
关于这个问题有什么想法吗?我是 jQuery 的新手,对此我一无所知......
附言: 我在 1.11.0 版中使用 jquery,以防相关。
最佳答案
尽管 const
is a Javascript 1.5 standard feature现代版本的 IE (6-10) 不支持它。
只有基于 gecko 的浏览器和 Chrome 支持它。
现在javascript中的变量使用var
,而不是const
来避免这个问题。
改变这个:
const visible = "visible";
const hidden = "hidden";
const open = "open";
对此:
var visible = "visible";
var hidden = "hidden";
var open = "open";
关于javascript - jQuery 脚本无法在 Internet Explorer 中运行(第 1 行第 1 个字符出现语法错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21911974/