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

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

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

var _806=$("<div class=\"datebox-button\"></div>").appendTo(_804);
$("<a href=\"javascript:void(0)\" class=\"datebox-current\"></a>").html(opts.currentText).appendTo(_806);
$("<a href=\"javascript:void(0)\" class=\"datebox-close\"></a>").html(opts.closeText).appendTo(_806);
var cl=$("<a href=\"javascript:void(0)\" class=\"datebox-clean\"></a>").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 = '清空';

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值