近期用了Easyui的日期控件datebox,項目中要將選中值清空,於是就研究了一下。
1。調用方法清空
$('#yourId').combo('setText','');
2,更改js文件
從官網下載的源文件里。datebox控件界面僅僅有‘Today’。‘Close’事件。我們能夠把清空選項值的事件加入到js中去,這樣,僅僅要引用了datebox這個控件,界面上就會有清空選項。詳細改動過程例如以下:
首先在官網上下載jquery.easyui.min.js文件。
在js文件里找到Today Close事件定義的地方,並加入Clean事件的定義。
源文件說明:
將源文件12733--12742行文件替換為:
代碼:
}},currentText:"Today",cleanText:"Clean",closeText:"Close",okText:"Ok",buttons:[{text:function(_985){ return $(_985).datebox("options").currentText; },handler:function(_986){ $(_986).datebox("calendar").calendar({year:new Date().getFullYear(),month:new Date().getMonth()+1,current:new Date()}); _975(_986); }},{text:function(_987){ return $(_987).datebox("options").closeText; },handler:function(_988){ $(this).closest("div.combo-panel").panel("close"); }},{ text : function(_989) { return $(_989).datebox("options").cleanText; },handler : function(_990) { $(_990).combo('setValue', '').combo('setText', ''); $(this).closest("div.combo-panel").panel("close"); }}],formatter:function(date){
界面效果例如以下:
3,中文js更改
上面我們把源js改好了,僅僅只是界面顯示的是英文,假設用了中文包的話,還須要更改easyui-lang-zh_CN.js
在js文件里找到‘今天’ ‘關閉 ’事件定義的地方,並加入‘清空’
代碼:
$.fn.datebox.defaults.currentText = '今天'; $.fn.datebox.defaults.closeText = '關閉'; $.fn.datebox.defaults.cleanText = '清空';
改動事件:
代碼:
if ($.fn.datetimebox && $.fn.datebox){ $.extend($.fn.datetimebox.defaults,{ cleanText: $.fn.datebox.defaults.cleanText, currentText: $.fn.datebox.defaults.currentText, closeText: $.fn.datebox.defaults.closeText, okText: $.fn.datebox.defaults.okText, missingMessage: $.fn.datebox.defaults.missingMessage }); }