在 this blog应该解释如何为所有日期时间输入实现 jquery 日期选择器。然而,当我尝试遵循所采取的步骤时,我惨遭失败。我怀疑我在某处设置了错误的引用,因为我的 VS 项目中现在已经有比博客中提到的更新的(且命名不同)的 .js 文件。有没有一个地方可以让绝对的 jquery NOOB 实现勺子喂养?
编辑: 我还找到了this link 。复制上述代码后,我在 jquery 1.5.1-min.js 中遇到了一个异常,该异常表示该对象不支持该属性或方法...
编辑(2) 我对此一筹莫展,我尝试添加 Tridus 建议的引用文献,但我有不同的版本,并且对于某些版本,我有一个 .min.js 替代方案。所有相关代码:
在 StandIn.cs 中:
[DisplayName("Available from")]
[DisplayFormat(DataFormatString="{0:d}",ApplyFormatInEditMode=true,NullDisplayText="(not specified")]
public DateTime? From { get; set; }
在Edit.cshtml中:
<div class="editor-field">
@Html.EditorFor(model => model.Standin.From)
@Html.ValidationMessageFor(model => model.Standin.From)
</div>
在_Layout.cshtml中:
<head>
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/themes/base/jquery.ui.all.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
</head>
在\Shared\EditorTemplates\DateTime.cshtml
@model Nullable<System.DateTime>
@if (Model.HasValue)
{
@Html.TextBox("", Model.Value.ToShortDateString(), new { @class = "date" })
}
else
{
@Html.TextBox("",string.Empty)
}
<script type="text/javascript">
$(document).ready(function () { $('.date').datepicker({ dateFormat: "dd/mm/yy" }); });
</script>
注意:所有代码都可以正常执行,直到我添加脚本标记:然后在显示 Edit.cshtml jquery-1.5.1.min.js 时会抛出有关不支持的属性或方法的异常。
最佳答案
这是一个很好的起点:http://jqueryui.com/demos/datepicker/
关于asp.net-mvc-3 - 在 ASP.Net MVC3 项目中使用 jquery datepicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7144736/