2017-03-08 117 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>