首页 > 代码库 > Knockout自定义绑定my97datepicker

Knockout自定义绑定my97datepicker

  不多说直接上代码。自定义绑定代码如下:

 1 /*             my97datepicker  时间格式‘yyyy-MM-dd HH-mm-ss‘           */ 2        ko.bindingHandlers.datetimes = { 3            init: function (element, valueAccessor, viewModel) { 4                var value =http://www.mamicode.com/ ko.utils.unwrapObservable(valueAccessor()); 5                $(element).attr("class", "Wdate"); 6                $(element).focus(function () { 7                    WdatePicker({ 8                        isShowClear: false, readOnly: true, dateFmt: ‘yyyy-MM-dd HH:mm:ss‘ 9                    });10                });11                $(element).val(value);12            },13            update: function (element, valueAccessor, viewModel) {14                var value =http://www.mamicode.com/ ko.utils.unwrapObservable(valueAccessor());15                $(element).val(value);16                $(element).blur(function () {17                    var v = $(element).val();18                    valueAccessor()(v);19                });20            }21        };

  Html代码如下:

1 <input id="date_times" data-bind="datetimes:forms.dates" data-options="required:true" style="width: 150px;" />