gpt4 book ai didi

javascript - 如何默认为日期选择器占位符?

转载 作者:行者123 更新时间:2023-11-29 17:00:50 25 4
gpt4 key购买 nike

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

<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'));

最佳答案

最简单的方法是:

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

但你也可以这样做:

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

请记住,DatePicker 中的 element 指的是原始 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"/>

关于javascript - 如何默认为日期选择器占位符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28180408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com