/* my97datepicker 时间格式'yyyy-MM-dd HH-mm-ss' */ ko.bindingHandlers.datetimes = { init: function (element, valueAccessor, viewModel) { var value = ko.utils.unwrapObservable(valueAccessor()); $(element).attr("class", "Wdate"); $(element).focus(function () { WdatePicker({ isShowClear: false, readOnly: true, dateFmt: 'yyyy-MM-dd HH:mm:ss' }); }); $(element).val(value); }, update: function (element, valueAccessor, viewModel) { var value = ko.utils.unwrapObservable(valueAccessor()); $(element).val(value); $(element).blur(function () { var v = $(element).val(); valueAccessor()(v); }); } };
<input id="date_times" data-bind="datetimes:forms.dates" data-options="required:true" style=" 150px;" />