1 Star 0 Fork 43

hattori/datepicker

forked from 笔心/jquery.datepicker 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
datepicker.min.js 4.98 KB
一键复制 编辑 原始数据 按行查看 历史
(function(e){var t='<div class="datepicker" id="datepicker"> <div class="top"> <div class="datepicker-select datepicker-select-year"> <div class="datepicker-select-selected"></div> <ul class="datepicker-select-option"> {{yearRange}} </ul> </div> <div class="datepicker-select datepicker-select-month"> <div class="datepicker-select-selected"></div> <ul class="datepicker-select-option"> <li data-month="1">&ensp;1月</li> <li data-month="2">&ensp;2月</li> <li data-month="3">&ensp;3月</li> <li data-month="4">&ensp;4月</li> <li data-month="5">&ensp;5月</li> <li data-month="6">&ensp;6月</li> <li data-month="7">&ensp;7月</li> <li data-month="8">&ensp;8月</li> <li data-month="9">&ensp;9月</li> <li data-month="10">10月</li> <li data-month="11">11月</li> <li data-month="12">12月</li> </ul> </div> </div> <table class="body"> <thead> <tr> <td class="cell week-cell">一</td> <td class="cell week-cell">二</td> <td class="cell week-cell">三</td> <td class="cell week-cell">四</td> <td class="cell week-cell">五</td> <td class="cell week-cell">六</td> <td class="cell week-cell">日</td> </tr> </thead> <tbody> </tbody> </table> <div class="bottom"> <div class="btn-clear">清空</div> </div> </div>';t=t.replace("{{yearRange}}",c());var a=e(t).appendTo(document.body);a.on("click",".datepicker-select",function(){var t=e(this).find(".datepicker-select-option");if(t.is(":hidden")){t.show()}else{t.hide()}}).on("click",".datepicker-select-option li",function(){var t=e(this).data("year")||e(".datepicker-select-year .datepicker-select-selected").data("year");var a=e(this).data("month")||e(".datepicker-select-month .datepicker-select-selected").data("month");l(t,a)}).on("mouseleave",".datepicker-select",function(){e(this).find(".datepicker-select-option").hide()}).on("click",".curr-month,.prev-month,.next-month",function(){a.find(".selected").removeClass("selected");e(this).addClass("selected");var t=e(this).data("value");var l=t.split("-");a._value={year:l[0]-0,month:l[1]-0,day:l[2]-0};a._bind.val(t);a.hide()}).on("click",".btn-clear",function(){a._bind.val("");a.hide()});e(document).on("mouseup",function(t){var l=e(t.target);if(a._instance){if(l.closest(".datepicker").length==0&&!l.is(a._bind)){a.hide()}}});function l(e,t){var l=[];var c=new Date(e,t-1,1);var s=c.getDay();if(s==0){s=7}if(s>1){c=new Date(e,t-1,0);var n=c.getDate();for(var r=s-2;r>=0;r--){l.push({value:d(c.getFullYear(),c.getMonth()+1,n-r),date:n-r,"class":"prev-month"})}}c=new Date(e,t,0);for(var r=1,o=c.getDate();r<=o;r++){l.push({value:d(e,t,r),date:r,"class":"curr-month"})}if(a._value.year==e&&a._value.month==t){l[s+a._value.day-2]["class"]+=" selected"}if(l.length%7>0){c=new Date(e,t,1);for(var r=1,o=7-l.length%7;r<=o;r++){l.push({value:d(c.getFullYear(),c.getMonth()+1,r),date:r,"class":"next-month"})}}a.find(".datepicker-select-year .datepicker-select-selected").data("year",e).text(e+"");a.find(".datepicker-select-month .datepicker-select-selected").data("month",t).text(t+"");a.find(".body tbody").html(i(l))}function i(e){var t=[];t.push("<tr>");for(var a=0,l=e.length;a<l;a++){t.push('<td class="cell '+e[a]["class"]+'" data-value="'+e[a]["value"]+'">'+e[a]["date"]+"</td>");if((a+1)%7==0&&a!=l-1){t.push("</tr></tr>")}}t.push("</tr>");return t.join("")}function c(){var e=new Date;var t=e.getFullYear()-5;var a=[];for(var l=0;l<12;l++){a.push('<li data-year="'+(t+l)+'">'+(t+l)+"年</li>")}return a.join("")}function d(e,t,a){t=t<10?"0"+t:t;a=a<10?"0"+a:a;return e+"-"+t+"-"+a}e.fn.datepicker=function(){var t=e(this);a._instance=true;t.on({focus:function(i){var c=e(this);var d=c.offset();a.css({top:d.top+c.outerHeight(),left:d.left});var s=t.val();var n=[];if(s==""){var r=new Date;n=[r.getFullYear(),r.getMonth()+1,r.getDate()]}else{n=s.split("-")}a._bind=t;a._value={year:n[0]-0,month:n[1]-0,day:n[2]-0};l(n[0]-0,n[1]-0);a.show()}})}})(jQuery);
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hattori/datepicker.git
[email protected]:hattori/datepicker.git
hattori
datepicker
datepicker
master

搜索帮助