EasyUI的datetimebox及datebox添加清空按鈕和日期選擇優化

關於EasyUI 的datetimebox選擇日期填充,網上例子太少,現在寫到下面供人蔘考,順便附上datebox的。

datebox的:

/**
 * 給時間框控件擴展一個清空的按鈕
 */
(function ($) {
    var buttons = $.extend([], $.fn.datebox.defaults.buttons);
    buttons.splice(1, 0, {
    	text: '清空',
        handler: function (target) {
            $(target).datebox('clear');
            $(target).datebox('hidePanel');
        }
    });
    $.extend($.fn.datebox.defaults, {
        buttons: buttons
    });

})(jQuery);

datetimebox的:

/**
 * 給時間框控件擴展一個清空的按鈕,且點擊日期時就自動選中
 */
(function ($) {
	var dt_buttons = $.extend([], $.fn.datetimebox.defaults.buttons);
    dt_buttons.splice(2, 0, {
        text: '清空',
        handler: function(target){
            $(target).datetimebox('clear');
            $(target).datetimebox('hidePanel');
        },
    });
    $.extend($.fn.datetimebox.defaults, {
    	buttons: dt_buttons,
        onSelect:function(date){
                var time=$(this).datetimebox('spinner').spinner('getValue');
                $(this).datetimebox('setValue',date.getFullYear()+'-'+ ((date.getMonth()+1)<10 ? ('0'+(date.getMonth()+1)) : (date.getMonth()+1))+'-'+((date.getDate())<10 ? ('0'+(date.getDate())) : (date.getDate()))+' '+time);
                $(this).datetimebox('hidePanel');
            }
    });
})(jQuery);

datetimebox的時分秒默認爲0,可以設置:

data-options=“
    editable:false,
    onShowPanel:function(){
       $(this).datetimebox(‘spinner’).timespinner(‘setValue’,‘23:59:59’);
    }
”

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章