【发布时间】:2015-03-21 05:10:55
【问题描述】:
我正在开发 mvc 网络应用程序。我在捆绑包中添加了以下脚本
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 上,而不是在捆绑中添加这些脚本,那么一切正常。我在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)
})
}
}();
【问题讨论】:
-
我的猜测是脚本在捆绑过程中被缩小并且缩小的变量相互覆盖。
-
@MikeLoffland 谢谢你的回复。 Burt 我从脚本中删除了
.min。 -
@MikeLoffland 我从我的解决方案中搜索了整个
cookie关键字,但没有找到任何东西。 -
如果你设置了BundleTable.EnableOptimizations = false,没有报错...证明缩小是原因。
-
脚本/jquery.scrollTo.min.js
标签: javascript c# asp.net-mvc