我的错误:jQuery的日期选择错误不是一个函数
Uncaught TypeError: $(...).datepicker is not a function
我把jQuery的参考束在头顶部分的布局,以确保它得到之前javascript函数加载。我做了视图源,并没有看到大于1个参照jquery的。 jquery版本是2.1.4。任何想法发生了什么?
我的观点:
<script type="text/javascript">
$(function() {
$('.date-picker').datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
}
});
});
</script>
<div class="form-group">
@Html.LabelFor(model => model.CCExpiration, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CCExpiration, new { htmlAttributes = new { @class = "form-control date-picker" } })
@Html.ValidationMessageFor(model => model.CCExpiration, "", new { @class = "text-danger" })
</div>
</div>
_layout
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - Vibe Productions Corporation</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
</head>
Bundles.cs
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery-ui-1.11.4/jquery-{version}.js"));
编辑,以显示我的包。但是,是的,我已经包括jQuery用户界面以及 – tshoemake
我被你用的OnClose函数做什么困惑。在日期选择器已经把选定的日期在文本框中,为什么要那样做动作? – Bindrid
@Bindrid,如果我没有的OnClose功能选择的日期不文本框里面保存了我 – tshoemake