【发布时间】:2014-12-22 15:59:37
【问题描述】:
当我在发布模式下发布我的应用时,日期选择器停止工作。
我很确定这与捆绑有关,但我不知道是什么
Jquery 和 Jquery UI 都以正确的顺序加载,并且只加载一次。
$.ui 也被初始化。
如果我尝试在谷歌浏览器控制台中绑定日期选择器
$("#birthdate").datepicker();
没有错误,但是没有绑定日期选择器,输入上没有hasDatepicker类
如果我尝试
$("#birthdate").datepicker("show");
我有以下错误
未捕获的类型错误:无法读取未定义的属性“应用”
因为日期选择器没有初始化
这是代码
<input class="form-control default-date-picker" data-msg-date="The field Birth Date must be a date." data-msg-required="The Birth Date field is required." data-rule-date="true" data-rule-required="true" id="birthdate" name="BirthDate" type="text" value="0001-01-01 12:00:00 AM" aria-required="true">
<script type='text/javascript'>
$(function () {
$("#birthdate").datepicker();
});
</script>
我无法解决问题
编辑
我注意到当我处于发布模式时,我从未在这些 jquery 函数中遇到断点
/* Attach the date picker to a jQuery selection.
* @param target element - the target input field or division or span
* @param settings object - the new settings to use for this date picker instance (anonymous)
*/
_attachDatepicker: function(target, settings) {
var nodeName, inline, inst;
nodeName = target.nodeName.toLowerCase();
inline = (nodeName === "div" || nodeName === "span");
if (!target.id) {
this.uuid += 1;
target.id = "dp" + this.uuid;
}
inst = this._newInst($(target), inline);
inst.settings = $.extend({}, settings || {});
if (nodeName === "input") {
this._connectDatepicker(target, inst);
} else if (inline) {
this._inlineDatepicker(target, inst);
}
},
/* Attach the date picker to an input field. */
_connectDatepicker: function(target, inst) {
var input = $(target);
inst.append = $([]);
inst.trigger = $([]);
if (input.hasClass(this.markerClassName)) {
return;
}
this._attachments(input, inst);
input.addClass(this.markerClassName).keydown(this._doKeyDown).
keypress(this._doKeyPress).keyup(this._doKeyUp);
this._autoSize(inst);
$.data(target, PROP_NAME, inst);
//If disabled option is true, disable the datepicker once it has been attached to the input (see ticket #5665)
if( inst.settings.disabled ) {
this._disableDatepicker( target );
}
},
捆绑代码
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery.unobtrusive-ajax.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/jquery-ui-1.10.4.js",
"~/Scripts/jquery-ui-i18n.js"));
脚本在 _layout.cs 的 <head> 部分呈现
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
【问题讨论】:
-
也许
<script type='text/javascript'>$(function(){ //your code });</script> -
对不起,我忘了在我的问题中包含这个。我的代码已经在脚本标签内。谢谢
-
调试方法如下:在浏览器中按 F12 并打开网络选项卡,重新创建错误,然后在浏览器中单击下载的文件列表。如果您看到 JQuery 已下载,请单击控制台选项卡并验证控制台没有引发错误。发回给我们,告诉我们您所看到的,我们将从那里开始。关于 Jquery 和 MVC 的一件令人抓狂的事情是 MVC 项目默认加载特定版本的 JQuery 和 Javascript,如果您曾经使用 NUGET 来获得某些东西,那么就有可能存在版本冲突。您也不想捆绑最小文件。
-
正如我所提到的,控制台中没有错误,我的包中没有 .min。我实在想不通问题所在。只有当
我有这个问题。并且 jquery 和 jquery ui 被加载,因为 $.ui 返回了一些东西。谢谢 -
你能发布你的捆绑代码吗?您在页面的哪个位置调用 Scripts.Render()(顶部或底部)?
标签: jquery asp.net jquery-ui bundling-and-minification