[英]ASP.NET MVC 4 jQuery Validation Script Bundle Not Working
我已經對網站進行了一次升級以使用ASP.NET MVC 4,並使用以下代碼來呈現我的jQuery驗證包。
但是我收到以下錯誤:
Microsoft JScript runtime error: Object doesn't support property or method 'live'
單擊文本框時出現此錯誤:
Unhandled exception at line 1234, column 5 in http://localhost:13112/Scripts/jquery.validate.js
0x800a138f - Microsoft JScript runtime error: Unable to get value of the property 'call': object is null or undefined
我的捆綁代碼:
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
我的_Layout.cshtml代碼:
@Styles.Render("~/Content/css")
@Styles.Render("~/Content/themes/base/css")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/bundles/modernizr")
這是我呈現的HTML:
<link href="/Content/site.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.core.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.resizable.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.selectable.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.accordion.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.autocomplete.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.button.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.dialog.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.slider.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.tabs.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.datepicker.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.progressbar.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.theme.css" rel="stylesheet"/>
<script src="/Scripts/jquery-1.9.0.js"></script>
<script src="/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>
<script src="/Scripts/jquery-ui-1.9.2.js"></script>
<script src="/Scripts/modernizr-2.6.2.js"></script>
有人能指出為什么會出現這種錯誤嗎?
謝謝,亞歷克斯。
.live方法已在jQuery v1.7 +中棄用,並在jQuery v1.9 +中刪除。
Bugreport: http ://bugs.jquery.com/ticket/13213
說明: http : //jquery.com/upgrade-guide/1.9/#live-removed
.live()已刪除
自jQuery 1.7以來,.live()方法已被棄用,並已在1.9中刪除。 我們建議升級代碼以使用.on()方法。 要完全匹配$(“a.foo”)。live(“click”,fn),例如,你可以寫$(document).on(“click”,“a.foo”,fn)。 有關更多信息,請參閱.on()文檔。 與此同時,jQuery Migrate插件可用於恢復.live()功能。
如何修復:下載jquery migrate插件並將其添加到您的捆綁:
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery-migrate-{version}.js"));
更新:現在可以從Nuget獲得遷移插件:
PM> Install-Package jQuery.Migrate
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.