2017-03-08 120 views
0

我有我的web应用程序中显示的jQuery UI日期选择器,但是当我去选择一个日期时,它不会执行任何操作。而默认的Html5 datepicker仍然显示。jQuery UI datepicker不工作?

My datepicker image

如何禁用HTML5的一个为jQuery UI的日期选择器的工作?

这是我做了我的代码:

Create.cshtml

@Html.LabelFor(model => model.EnrollmentDate, htmlAttributes: new { @class = "control-label col-md-2" }) 
       <div class="col-md-10"> 
        @Html.EditorFor(model => model.EnrollmentDate, new { htmlAttributes = new { @class = "form-control", @id = "datepicker" } }) 
        @Html.ValidationMessageFor(model => model.EnrollmentDate, "", new { @class = "text-danger" }) 

........ 

@section Scripts { 
<script> 
    $(document).ready(function(){ 
     $('#datepicker').datepicker({ 
     dateFormat: 'dd-mm-yy' 
     }); 
    }); 
</script>   
    @Scripts.Render("~/bundles/jqueryval") 
} 

回答

0

你可以去内建日期选取器。 请参考https://jqueryui.com/datepicker/

+0

我使用该链接为我的代码编写脚本。 Chrome控制台显示错误,例如“jQuery ui','css' ...”无法加载资源......“ – Afton

0

我只需要为@Html.EditFor输入一个文本类型,它就起作用了。试图使用@Html.TextBoxFor没有为我工作。

@Html.EditorFor(model => model.EnrollmentDate, new { htmlAttributes = new { @class = "form-control", @type = "text" } }) 

<script> 
    $(function(){ 
     $('#EnrollmentDate').datepicker({ 
      changeMonth: true, 
      changeYear: true 
     }); 
    }); 
</script>