jQuery EasyUI 1.3.2 日期控件 加入清空按钮

在使用easyui日期插件时,为了规范输入一般需要对输入框添加只读属性禁止输入。但如果日期值是可选时就会出现问题:无法清空值。旁边再制作专门清空按钮未免太费事,所以可以对源码改造一下。以下以jQuery EasyUI 1.3.2为例。

打开jquery.easyui.min.js 约10907行:

var _806=$("

").appendTo(_804);
$("").html(opts.currentText).appendTo(_806);
$("").html(opts.closeText).appendTo(_806);
var cl=$("").html(opts.cleanText).appendTo(_806);
_806.find(".datebox-current,.datebox-close").hover(function(){
$(this).addClass("datebox-button-hover");
},function(){
$(this).removeClass("datebox-button-hover");
});
_806.find(".datebox-current").click(function(){
_802.calendar.calendar({year:new Date().getFullYear(),month:new Date().getMonth()+1,current:new Date()});
});
_806.find(".datebox-close").click(function(){
$(_801).combo("hidePanel");
});
cl.click(function(){
    _809(_801,"");//或$(_801).combo("setValue","").combo("setText","");
    $(_801).combo("hidePanel");
});

然后在10990行左右:
}},currentText:"Today",closeText:"Close",okText:"Ok",cleanText:"Clean",formatter:function(date){

说明:红色的为添加的脚本,其中_809(_801,"");是调用easyUI内置日期赋值函数。$(_801).combo("setValue","")是对真实input赋值,$(_801).combo("setText","")是对插件赋值。

然后打开:themes/default/easyui.css 约1440行:

.datebox-current,
.datebox-close,
.datebox-ok,.datebox-clean {
  text-decoration: none;
  font-weight: bold;
  opacity: 0.6;
  filter: alpha(opacity=60);
}
.datebox-clean{float:center}
/*再下几行.........*/
.datebox-current,
.datebox-close,
.datebox-ok,.datebox-clean {
  color: #444;
}

说明:如果你使用的是其他风格,同理修改其他easyui.css文件。最后打开locale/easyui-lang-zh_CN.js约40行:
$.fn.datebox.defaults.cleanText = '清空';

jQuery EasyUI 1.3.2 日期控件 加入清空按钮_第1张图片

你可能感兴趣的:(组件)