我正在开发MVC Web应用程序。我在捆绑中添加了以下脚本
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运行时错误:对象不支持属性或方法“ cookie”
如果我将这些脚本添加到捆绑包中,而不是将它们添加到捆绑包中,_LayOut.cshtml
那么一切都很好。我已经添加BundleTable.EnableOptimizations = true;
了Bundle.config
。我不明白问题出在哪里。有人可以帮我解决这个问题吗?我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/
因此,您的捆绑包将类似于:
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.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句