我正在尝试使用 JQuery UI 日期选择器,但它仅显示为普通文本框。当我打开 Google Chrome 调试器时,出现一个错误“Uncaught TypeError: $(...).datepicker is not a function”
这是我的 Bundle.config 文件
using System.Web;
using System.Web.Optimization;
namespace ultimateorganiser
{
public class BundleConfig
{
// For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery - ui.min.js",
"~/Scripts/Scripts/jquery-ui.js",
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js"));
//JQuery bxSlider
bundles.Add(new ScriptBundle("~/bundles/slider").Include(
"~/Scripts/jquery.bxslider.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/jquery - ui.css",
"~/Content/site.css"));
}
}
}
这是我的 View ,脚本代码位于底部
@model ultimateorganiser.Models.ClubMember
@{
ViewBag.Title = "Register";
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
//UserDob
<div class="form-group">
@Html.LabelFor(model => model.UserDoB, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserDoB, new { id = "userdob" })
@Html.ValidationMessageFor(model => model.UserDoB, "", new { @class = "text-danger" })
</div>
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script>
$(document).ready(function () {
$("#news_date").datepicker({ dateFormat: 'dd/mm/yy' });
});
</script>
}
最佳答案
我认为您需要在 View 中添加 @Scripts.Render("~/bundles/jquery")
。
关于javascript - JQuery-UI 日期选择器无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34201346/