我正在开发 MVC Web 应用程序。我在 bundle 中添加了以下脚本
bundles.Add(new ScriptBundle("~/bundles/adminscripts").Include(
"~/Scripts/jquery.js",
"~/Scripts/bootstrap.js",
"~/Scripts/jquery.dcjqaccordion.2.7.js",
"~/Scripts/jquery.scrollTo.min.js",
"~/Scripts/jquery.nicescroll.js",
"~/Scripts/jquery.sparkline.js",
"~/Scripts/assets/jquery-easy-pie-chart/jquery.easy-pie-chart.js",
"~/Scripts/owl.carousel.js",
"~/Scripts/jquery.customSelect.js",
"~/Scripts/respond.js",
"~/Scripts/slidebars.js",
"~/Scripts/common-scripts.js",
"~/Scripts/sparkline-chart.js",
"~/Scripts/easy-pie-chart.js",
"~/Scripts/count.js",
"~/Scripts/Main.js"));
当我运行该网站时,它给了我这个错误
0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'cookie'
如果我将这些脚本添加到我的 _LayOut.cshtml
上,那么一切都会正常工作,而不是在 bundle 中添加这些脚本。我已在 Bundle.config
中添加了 BundleTable.EnableOptimizations = true;
。我不明白问题出在哪里。有人可以帮我解决这个问题吗?我从我的解决方案中搜索了整个 cookie
关键字,但没有找到任何内容。请看下面的截图
我已使用 nugget 命令行包管理器升级了我的脚本。但我的问题仍然没有解决。我发现导致问题的脚本。
编辑
~/Scripts/common-scripts.js 这个脚本给我错误。
这是脚本代码
/*---LEFT BAR ACCORDION----*/
$(function () {
$('#nav-accordion').dcAccordion({
eventType: 'click',
autoClose: true,
saveState: true,
disableLink: true,
speed: 'slow',
showCount: false,
autoExpand: true,
// cookie: 'dcjq-accordion-1',
classExpand: 'dcjq-current-parent'
});
});
// right slidebar
$(function () {
$.slidebars();
});
var Script = function () {
// sidebar dropdown menu auto scrolling
jQuery('#sidebar .sub-menu > a').click(function () {
var o = ($(this).offset());
diff = 250 - o.top;
if (diff > 0)
$("#sidebar").scrollTo("-=" + Math.abs(diff), 500);
else
$("#sidebar").scrollTo("+=" + Math.abs(diff), 500);
});
// sidebar toggle
$(function () {
function responsiveView() {
var wSize = $(window).width();
if (wSize <= 768) {
$('#container').addClass('sidebar-close');
$('#sidebar > ul').hide();
}
if (wSize > 768) {
$('#container').removeClass('sidebar-close');
$('#sidebar > ul').show();
}
}
$(window).on('load', responsiveView);
$(window).on('resize', responsiveView);
});
$('.fa-bars').click(function () {
if ($('#sidebar > ul').is(":visible") === true) {
$('#main-content').css({
'margin-left': '0px'
});
$('#sidebar').css({
'margin-left': '-210px'
});
$('#sidebar > ul').hide();
$("#container").addClass("sidebar-closed");
} else {
$('#main-content').css({
'margin-left': '210px'
});
$('#sidebar > ul').show();
$('#sidebar').css({
'margin-left': '0'
});
$("#container").removeClass("sidebar-closed");
}
});
// custom scrollbar
$("#sidebar").niceScroll({ styler: "fb", cursorcolor: "#e8403f", cursorwidth: '3', cursorborderradius: '10px', background: '#404040', spacebarenabled: false, cursorborder: '' });
$("html").niceScroll({ styler: "fb", cursorcolor: "#e8403f", cursorwidth: '6', cursorborderradius: '10px', background: '#404040', spacebarenabled: false, cursorborder: '', zindex: '1000' });
// widget tools
jQuery('.panel .tools .fa-chevron-down').click(function () {
var el = jQuery(this).parents(".panel").children(".panel-body");
if (jQuery(this).hasClass("fa-chevron-down")) {
jQuery(this).removeClass("fa-chevron-down").addClass("fa-chevron-up");
el.slideUp(200);
} else {
jQuery(this).removeClass("fa-chevron-up").addClass("fa-chevron-down");
el.slideDown(200);
}
});
// by default collapse widget
// $('.panel .tools .fa').click(function () {
// var el = $(this).parents(".panel").children(".panel-body");
// if ($(this).hasClass("fa-chevron-down")) {
// $(this).removeClass("fa-chevron-down").addClass("fa-chevron-up");
// el.slideUp(200);
// } else {
// $(this).removeClass("fa-chevron-up").addClass("fa-chevron-down");
// el.slideDown(200); }
// });
jQuery('.panel .tools .fa-times').click(function () {
jQuery(this).parents(".panel").parent().remove();
});
// tool tips
$('.tooltips').tooltip();
// popovers
$('.popovers').popover();
// custom bar chart
if ($(".custom-bar-chart")) {
$(".bar").each(function () {
var i = $(this).find(".value").html();
$(this).find(".value").html("");
$(this).find(".value").animate({
height: i
}, 2000)
})
}
}();
最佳答案
查看 dcjqAccordian 的源代码,它尝试调用 $.cookie
来保存其状态。您需要添加 jQuery.Cookie 作为脚本才能使其正常工作:https://github.com/carhartl/jquery-cookie或https://www.nuget.org/packages/jquery.cookie/
因此,您的 bundle 将类似于:
bundles.Add(new ScriptBundle("~/bundles/adminscripts").Include(
"~/Scripts/jquery.js",
"~/Scripts/jquery.cookie.*",
"~/Scripts/bootstrap.js",
"~/Scripts/jquery.dcjqaccordion.2.7.js",
... etc.
顺便说一句,我会避免使用简单的“jquery.js”引用;假设您使用 NuGet 包,您通常会使用:
bundles.Add(new ScriptBundle("~/bundles/adminscripts").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery.cookie.*",
"~/Scripts/bootstrap.js",
"~/Scripts/jquery.dcjqaccordion.2.7.js",
... etc.
关于javascript - 0x800a01b6 - JavaScript 运行时错误 : Object doesn't support property or method 'cookie' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29179486/