根据在文本控件中输入的值更新 kendo 日期时间控件中的月份

Updating the month in kendo datetime control based on value entered in the text control

我正在处理 MVC 应用程序。尝试根据文本框控件的更改事件将月份添加到 Kendo MVC Datetimepicker 控件。
当用户在 Contract Duration 字段中输入月份时,它应该添加 Priority Date 时间控制。

有人可以建议如何做到这一点。

合同期限(月)

  <div class="form-group">
                    @Html.LabelFor(model => model.ContractDurationInMonths, htmlAttributes: new { @class = "control-label col-md-4" })
                    <div class="col-md-8">
                        @Html.EditorFor(model => model.ContractDurationInMonths, new { htmlAttributes = new { @class = "form-control", style = "width:100%" } })
                        @Html.ValidationMessageFor(model => model.ContractDurationInMonths, "", new { @class = "text-danger" })
                    </div>
                </div>

优先日期时间控制

<div class="form-group">
                    @Html.LabelFor(model => model.Priority, htmlAttributes: new { @class = "control-label col-md-4" })
                    <div class="col-md-8">
                        @*@Html.EditorFor(model => model.Priority, new { htmlAttributes = new { @class = "form-control" } })*@
                        @(Html.Kendo().DatePickerFor(model => model.Priority)
                          .Name("Priority")
                          .Value("10/10/2011")
                          .HtmlAttributes(new { style = "width: 100%" })
                        )
                        @Html.ValidationMessageFor(model => model.Priority, "", new { @class = "text-danger" })
                    </div>
                </div>

基本上,在文本框上设置 blur() 事件,然后更新日期选择器的值:

<script>
    $(document).ready(function() {

        $("#ContractDurationInMonths").blur(function () {
                var date = $("#Priority").data("kendoDatePicker").value();
                var newMonth = date.getMonth() + kendo.parseInt($("#ContractDurationInMonths").val());
                date.setMonth(newMonth);
                $("#Priority").data("kendoDatePicker").value(date);
         });              


    });
</script>

这是一个 js 示例:http://dojo.telerik.com/@sg53719/eseRo