jQuery Microsoft JScript 运行时错误:对象不支持“实时”属性或方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14774836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Microsoft JScript runtime error: Object doesn't support property or method 'live'?
提问by Raja
I am clicking on button the following error is shown "Microsoft JScript runtime error: Object doesn't support property or method 'live'"My View page is as follows:
我单击按钮时显示以下错误“Microsoft JScript 运行时错误:对象不支持属性或方法‘live’”我的视图页面如下:
@model Charis.Models.Products
@{
ViewBag.Title = "Create";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<link href="../../Content/CharisSite.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
@using (Html.BeginForm("Create", "Prod", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
<table><tr><td>
<table>
<tr>
<td>
<fieldset>
<legend>Products</legend>
<table>
<tr>
<td>
<div class="editor-label">
@Html.LabelFor(model => model.Productname)
</div>
</td>
<td>
<div class="editor-field">
@Html.EditorFor(model => model.Productname)
@Html.ValidationMessageFor(model => model.Productname)
</div>
</td>
</tr>
<tr>
<td>
<div class="editor-label">
@Html.LabelFor(model => model.ProductPrice)
</div>
</td>
<td>
<div class="editor-field">
@Html.EditorFor(model => model.ProductPrice)
@Html.ValidationMessageFor(model => model.ProductPrice)
</div>
</td>
</tr>
<tr>
<td>
<div class="editor-label">
@Html.LabelFor(model => model.ProductDiscount)
</div>
</td>
<td>
<div class="editor-field">
@Html.EditorFor(model => model.ProductDiscount)
@Html.ValidationMessageFor(model => model.ProductDiscount)
</div>
</td>
</tr>
<tr>
<td>
<div class="editor-label">
@Html.LabelFor(model => model.LanguageType)
</div>
</td>
<td>
<div class="editor-field">
@Html.EditorFor(model => model.LanguageType)
@Html.ValidationMessageFor(model => model.LanguageType)
</div>
</td>
</tr>
<tr>
<td>
<div class="editor-label">
@Html.LabelFor(model => model.ReleaseDate)
</div>
</td>
<td>
<div class="editor-field">
@Html.EditorFor(model => model.ReleaseDate)
@Html.ValidationMessageFor(model => model.ReleaseDate)
</div>
</td>
</tr>
<tr>
<td>
<div class="editor-label">
<label for="file">Upload Image:</label>
</div>
</td>
<td>
<div class="editor-field">
<input type="file" name="file" id="file"/>
</div>
</td>
</tr>
</table>
</fieldset>
</td>
<td></td></tr>
</table>
</td></tr>
<tr><td>
<table>
<tr>
<td>
<fieldset>
<legend>Details</legend>
<table>
<tr>
<td>
<div class="editor-label">
@Html.LabelFor(model => model.AlbumDescription1)
</div>
</td>
<td>
<div class="editor-field">
@Html.EditorFor(model => model.AlbumDescription1)
@Html.ValidationMessageFor(model => model.AlbumDescription1)
</div>
</td>
</tr>
<tr>
<td>
<div class="editor-label">
@Html.LabelFor(model => model.AlbumDescription2)
</div>
</td>
<td>
<div class="editor-field">
@Html.EditorFor(model => model.AlbumDescription2)
@Html.ValidationMessageFor(model => model.AlbumDescription2)
</div>
</td>
</tr>
<tr>
<td>
<div class="editor-label">
@Html.LabelFor(model => model.Cast)
</div>
</td>
<td>
<div class="editor-field">
@Html.EditorFor(model => model.Cast)
@Html.ValidationMessageFor(model => model.Cast)
</div>
</td>
</tr>
<tr>
<td>
<div class="editor-label">
@Html.LabelFor(model => model.DirectedBy)
</div>
</td>
<td>
<div class="editor-field">
@Html.EditorFor(model => model.DirectedBy)
@Html.ValidationMessageFor(model => model.DirectedBy)
</div>
</td>
</tr>
<tr>
<td>
<div class="editor-label">
@Html.LabelFor(model => model.ProducedBy)
</div>
</td>
<td>
<div class="editor-field">
@Html.EditorFor(model => model.ProducedBy)
@Html.ValidationMessageFor(model => model.ProducedBy)
</div>
</td>
</tr>
<tr>
<td>
<div class="editor-label">
<label for="file">Upload Image1:</label>
</div>
</td>
<td>
<div class="editor-field">
<input type="file" name="file1" id="file1"/>
</div>
</td>
</tr>
<tr>
<td>
<div class="editor-label">
<label for="file">Upload Image2:</label>
</div>
</td>
<td>
<div class="editor-field">
<input type="file" name="file2" id="file2"/>
</div>
</td>
</tr>
<tr>
<td>
<div class="editor-label">
<label for="file">Upload Image3:</label>
</div>
</td>
<td>
<div class="editor-field">
<input type="file" name="file3" id="file3"/>
</div>
</td>
</tr>
<tr>
<td>
<div class="editor-label">
<label for="file">Upload Image4:</label>
</div>
</td>
<td>
<div class="editor-field">
<input type="file" name="file4" id="file4"/>
</div>
</td>
</tr>
<tr>
<td>
<div class="editor-label">
<label for="file">Upload Image5:</label>
</div>
</td>
<td>
<div class="editor-field">
<input type="file" name="file5" id="file5"/>
</div>
</td>
</tr>
<tr>
<td>
<div class="editor-label">
@Html.LabelFor(model => model.NoOfDisk)
</div>
</td>
<td>
<div class="editor-field">
@Html.EditorFor(model => model.NoOfDisk)
@Html.ValidationMessageFor(model => model.NoOfDisk)
</div>
</td>
</tr>
<tr>
<td>
<div class="editor-label">
@Html.LabelFor(model => model.Weight)
</div>
</td>
<td>
<div class="editor-field">
@Html.EditorFor(model => model.Weight)
@Html.ValidationMessageFor(model => model.Weight)
</div>
</td>
</tr>
<tr>
<td>
<div class="editor-label">
@Html.LabelFor(model => model.Format)
</div>
</td>
<td>
<div class="editor-field">
@Html.EditorFor(model => model.Format)
@Html.ValidationMessageFor(model => model.Format)
</div>
</td>
</tr>
</table>
</fieldset>
</td>
</tr>
</table>
</td></tr>
<tr><td>
<table><tr><td><fieldset><table>
<tr>
<td>
<p>
<input type="submit" value="Create" />
<input type="button" value="Clear" id="btnClear" />
</p>
</td>
</tr>
</table></fieldset></td></tr></table>
</td></tr>
</table>
}
@*<div>
@Html.ActionLink("Back to List", "Index")
</div>
*@
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
@if (TempData["notice"] != null)
{
<p style="color:Red;" >@TempData["notice"]</p>
}
回答by mikakun
you are using jquery latest (1.9...) in which $(sel).live(...)
was deprecated hence your error message.
您正在使用 jquery latest (1.9 ...),其中$(sel).live(...)
已弃用,因此您的错误消息。
1) revert to an older version of jquery.
1) 恢复到旧版本的 jquery。
2) update your code (replace live by on).
2) 更新您的代码(实时替换)。
3) put back jquery-latest.
3)放回jquery-latest。
回答by Nick Albrecht
You can also look into including jQuery Migrate to help with upgrading to jQuery 1.9
您还可以考虑包含 jQuery Migrate 以帮助升级到 jQuery 1.9
回答by Elsimer
I just ran across this after updating to jQuery 1.9 myself. However, I notice that none of the users (except AliR?za Ad?yah?i in a link with no explanation) previously pointed out what part of your code was causing the error. After all, if
$(sel).live(...)
was deprecated in favor of $(sel).on(...)
then it's a pretty simple fix, right?
我自己更新到 jQuery 1.9 后就遇到了这个问题。但是,我注意到没有任何用户(除了 AliR?za Ad?yah?i 在没有解释的链接中)之前指出您的代码的哪一部分导致了错误。毕竟,如果
$(sel).live(...)
被弃用,$(sel).on(...)
那么这是一个非常简单的修复,对吧?
The problem is that this error is being thrown inside jquery.unobtrusive-ajax.js
, which you include as part of the bundle in @Scripts.Render("~/bundles/jqueryval")
问题是这个错误被抛出到里面jquery.unobtrusive-ajax.js
,你把它作为包的一部分包含在@Scripts.Render("~/bundles/jqueryval")
Since you aren't using the Ajax form or cancel, the error is unlikely to affect anything (it doesn't on mine) but I was unable to find anything from Microsoft on a fix. The fix, unfortunately, is to go in and fix your version of jquery.unobtrusive-ajax.js replacing the .live calls to .on() until MS fixes the official one.
由于您没有使用 Ajax 表单或取消,该错误不太可能影响任何事情(它不在我的身上),但我无法从 Microsoft 找到任何有关修复程序的信息。不幸的是,修复是进入并修复您的 jquery.unobtrusive-ajax.js 版本,替换对 .on() 的 .live 调用,直到 MS 修复官方调用。