2

这是我的日期选择器的代码:

<div class="editor-field">
                    @(Html.Kendo().DatePickerFor(model => model.Date)
                        .HtmlAttributes(ViewBag.Disabled ? (object)new { @class = "formDatePicker", disabled = "disabled", @id = "Date", style = "width:150px", placeholder = "Select Date" } : new { @class = "formDatePicker", @id = "Date", style = "width:150px", placeholder = "Select Date" })
                        .Events(e => e.Open(@<text>function(e){BrowserCompatibility.DisableDatePickerYearsOnSomeBrowsers(e);}</text>))
                        .Format(@HCulture.GetShortDateFormat())
                        .Events(e => e.Change(@<text>function(e){
                            $("#DateString").val($('#Date').val());
                            checkInputValid();
                            }</text>))
                    )
                </div>

我尝试了这个解决方案,但没有奏效:

 var datePicker = $("#Date").data('kendoDatePicker');
 datePicker.input.val(input.attr('placeholder'));
4

1 回答 1

5

最简单的方法是:

$("#Date").attr("placeholder", "type date");

但你也可以这样做:

var datePicker = $("#Date").data('kendoDatePicker');
datePicker.element.attr("placeholder", "type date");

请记住,elementinDatePicker指的是原始input元素。

检查以下代码片段中的两种方法。

$(document).ready(function() {
  $("#Date").kendoDatePicker({
  });

  $("#change1").on("click", function() {
    $("#Date").attr("placeholder", "type date 1");
  });
  $("#change2").on("click", function() {
    var datePicker = $("#Date").data('kendoDatePicker');
    datePicker.element.attr("placeholder", "type date 2");
  });
});
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1316/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1316/styles/kendo.default.min.css">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://cdn.kendostatic.com/2014.3.1316/js/kendo.web.min.js"></script>

<button class="k-button" id="change1">Change Method 1</button>
<button class="k-button" id="change2">Change Method 2</button>
<input id="Date" disabled="disabled"/>

于 2015-01-27T22:33:24.593 回答