How Do I Raise the Change Event in the KendoUI DatePicker?

左心房为你撑大大i 提交于 2019-12-12 10:33:16

问题


I'm trying to set the value of my DatePicker using the code below and expecting the "Change" event to be raise but it doesn't.

var datePicker = $("#datePicker").data("kendoDatePicker");
var previousDate = new Date(datePicker.value());
previousDate.setDate(previousDate.getDate() - 1);
$("#displayDate").text(kendo.toString(new Date(previousDate), 'D'));
datePicker.value(previousDate);

Change the date value through the user interface does raise the "Change" event as expected however.


回答1:


Please try with the below code snippet.

HTML

<input id="datepicker" />
<input type="button" value="set date" onclick="setdateInDP()">

JS

<script type="text/javascript">
$(document).ready(function () {
    function onChange() {
        alert("Change :: " + kendo.toString(this.value(), 'd'));
    }

    $("#datepicker").kendoDatePicker({
        change: onChange
    });
});

function setdateInDP() {
    var datePicker = $("#datepicker").data("kendoDatePicker");
    var previousDate = new Date(datePicker.value());
    previousDate.setDate(previousDate.getDate() - 1);
    datePicker.value(previousDate);
    $("#datepicker").data("kendoDatePicker").trigger("change");
}



来源:https://stackoverflow.com/questions/15716402/how-do-i-raise-the-change-event-in-the-kendoui-datepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!