十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
使用jquery 日期控件的步骤
创新互联是一家专业提供揭西企业网站建设,专注与成都网站建设、成都网站设计、H5响应式网站、小程序制作等业务。10年已为揭西众多企业、政府机构等服务。创新互联专业网站设计公司优惠进行中。
下载JQuery UI的Datepicker
修改源码实现中文日期选择器
在SpreadJS创建CustomCellType
实现CustomCellType的activateEditor和deactivateEditor方法
实现setEditorValue和getEditorValue方法
实现updateEditor方法
在SpreadJS中调用
具体的代码实现,可以参考下面的博客
网络不好。使用jquery日期控件设置日期时,会自动连接网络进行查找日期,网络不好就会出现只有每月的1号可以选的现象,只要连接较好的网络即可解决。
;!function(a){var b={path:"",defSkin:"",format:"YYYY-MM-DD",min:"1900-01-01 00:00:00",max:"2099-12-31 23:59:59",isv:!1},c={},d=document,e="createElement",f="getElementById",g="getElementsByTagName",h=["laydate_box","laydate_void","laydate_click","LayDateSkin","","abc.css"];a.laydate=function(b){b=b||{};try{a.event=a.event||laydate.caller.arguments[0]}catch(d){}return a.event(b.tagName=1),c.run(b),laydate},laydate.v="1.1",c.getPath=function(){var a=document.scripts,c=a[a.length-1].src;return b.path?b.path:c.substring(0,c.lastIndexOf("/")+1)}(),c.use=function(a,b){var f=d[e]("link");f.type="text/css",f.rel="stylesheet",f.href=c.getPath+a+h[5],b(f.id=b),d[g]("head")[0].appendChild(f),f=null},c.trim=function(a){return a=a||"",a.replace(/^\s|\s$/g,"").replace(/\s+/g," ")},c.digit=function(a){return 10a?"0"+(0|a):a},c.stopmp=function(b){return b=b||a.event,b.stopPropagation?b.stopPropagation():b.cancelBubble=!0,this},c.each=function(a,b){for(var c=0,d=a.length;dcb(c,a[c])!==!1;c++);},c.hasClass=function(a,b){return a=a||{},new RegExp("\\b"+b+"\\b").test(a.className)},c.addClass=function(a,b){return a=a||{},c.hasClass(a,b)||(a.className+=" "+b),a.className=c.trim(a.className),this},c.removeClass=function(a,b){if(a=a||{},c.hasClass(a,b)){var d=new RegExp("\\b"+b+"\\b");a.className=a.className.replace(d,"")}return this},c.removeCssAttr=function(a,b){var c=a.style;c.removeProperty?c.removeProperty(b):c.removeAttribute(b)},c.shde=function(a,b){a.style.display=b?"none":"block"},c.query=function(a){var e,b,h,i,j;return a=c.trim(a).split(" "),b=d[f](a[0].substr(1)),b?a[1]?/^\./.test(a[1])?(i=a[1].substr(1),j=new RegExp("\\b"+i+"\\b"),e=[],h=d.getElementsByClassName?b.getElementsByClassName(i):b[g]("*"),c.each(h,function(a,b){j.test(b.className)e.push(b)}),e[0]?e:""):(e=b[g](a[1]),e[0]?b[g](a[1]):""):b:void 0},c.on=function(b,d,e){return b.attachEvent?b.attachEvent("on"+d,function(){e.call(b,a.even)}):b.addEventListener(d,e,!1),c},c.stopMosup=function(a,b){"mouseup"!==ac.on(b,"mouseup",function(a){c.stopmp(a)})},c.run=function(a){var d,e,b=c.query;if(a.tagName){if(d=a.elem?b(a.elem):event.target||event.srcElement,!d||d===c.elem)return;c.view(d,a),c.stopMosup(event.type,d),c.reshow()}else{if(d=b(a.elem),!d)return;e=a.event||"click",c.each((0|d.length)0?d:[d],function(b,d){c.on(d,e,function(b){c.stopmp(b),d!==c.elem(c.view(d,a),c.reshow())}),c.stopMosup(e,d)})}},c.scroll=function(a){return a=a?"scrollLeft":"scrollTop",d.body[a]|d.documentElement[a]},c.winarea=function(a){return document.documentElement[a?"clientWidth":"clientHeight"]},c.isleap=function(a){return 0===a%40!==a%100||0===a%400},c.checkVoid=function(a,b,d){var e=[];return a=0|a,b=0|b,d=0|d,ac.mins[0]?e=["y"]:ac.maxs[0]?e=["y",1]:a=c.mins[0]a=c.maxs[0](a==c.mins[0](bc.mins[1]?e=["m"]:b==c.mins[1]dc.mins[2](e=["d"])),a==c.maxs[0](bc.maxs[1]?e=["m",1]:b==c.maxs[1]dc.maxs[2](e=["d",1]))),e},c.timeVoid=function(a,b){if(c.ymd[1]+1==c.mins[1]c.ymd[2]==c.mins[2]){if(0===bac.mins[3])return 1;if(1===bac.mins[4])return 1;if(2===bac.mins[5])return 1}else if(c.ymd[1]+1==c.maxs[1]c.ymd[2]==c.maxs[2]){if(0===bac.maxs[3])return 1;if(1===bac.maxs[4])return 1;if(2===bac.maxs[5])return 1}return a(b?59:23)?1:void 0},c.check=function(){var a=c.options.format.replace(/YYYY|MM|DD|hh|mm|ss/g,"\\d+\\").replace(/\\$/g,""),b=new RegExp(a),d=c.elem[h.elemv],e=d.match(/\d+/g)||[],f=c.checkVoid(e[0],e[1],e[2]);if(""!==d.replace(/\s/g,"")){if(!b.test(d))return c.elem[h.elemv]="",c.msg("日期不符合格式,请重新选择。"),1;if(f[0])return c.elem[h.elemv]="",c.msg("日期不在有效期内,请重新选择。"),1;f.value=c.elem[h.elemv].match(b).join(),e=f.value.match(/\d+/g),e[1]1?(e[1]=1,f.auto=1):e[1]12?(e[1]=12,f.auto=1):e[1].length2(f.auto=1),e[2]1?(e[2]=1,f.auto=1):e[2]c.months[(0|e[1])-1]?(e[2]=31,f.auto=1):e[2].length2(f.auto=1),e.length3(c.timeVoid(e[3],0)(f.auto=1),c.timeVoid(e[4],1)(f.auto=1),c.timeVoid(e[5],2)(f.auto=1)),f.auto?c.creation([e[0],0|e[1],0|e[2]],1):f.value!==c.elem[h.elemv](c.elem[h.elemv]=f.value)}},c.months=[31,null,31,30,31,30,31,31,30,31,30,31],c.viewDate=function(a,b,d){var f=(c.query,{}),g=new Date;a(0|c.mins[0])(a=0|c.mins[0]),a(0|c.maxs[0])(a=0|c.maxs[0]),g.setFullYear(a,b,d),f.ymd=[g.getFullYear(),g.getMonth(),g.getDate()],c.months[1]=c.isleap(f.ymd[0])?29:28,g.setFullYear(f.ymd[0],f.ymd[1],1),f.FDay=g.getDay(),f.PDay=c.months[0===b?11:b-1]-f.FDay+1,f.NDay=1,c.each(h.tds,function(a,b){var g,d=f.ymd[0],e=f.ymd[1]+1;b.className="",af.FDay?(b.innerHTML=g=a+f.PDay,c.addClass(b,"laydate_nothis"),1===e(d-=1),e=1===e?12:e-1):a=f.FDayaf.FDay+c.months[f.ymd[1]]?(b.innerHTML=g=a-f.FDay+1,a-f.FDay+1===f.ymd[2](c.addClass(b,h[2]),f.thisDay=b)):(b.innerHTML=g=f.NDay++,c.addClass(b,"laydate_nothis"),12===e(d+=1),e=12===e?1:e+1),c.checkVoid(d,e,g)[0]c.addClass(b,h[1]),c.options.festivalc.festival(b,e+"."+g),b.setAttribute("y",d),b.setAttribute("m",e),b.setAttribute("d",g),d=e=g=null}),c.valid=!c.hasClass(f.thisDay,h[1]),c.ymd=f.ymd,h.year.value=c.ymd[0]+"年",h.month.value=c.digit(c.ymd[1]+1)+"月",c.each(h.mms,function(a,b){var d=c.checkVoid(c.ymd[0],(0|b.getAttribute("m"))+1);"y"===d[0]||"m"===d[0]?c.addClass(b,h[1]):c.removeClass(b,h[1]),c.removeClass(b,h[2]),d=null}),c.addClass(h.mms[c.ymd[1]],h[2]),f.times=[0|c.inymd[3]||0,0|c.inymd[4]||0,0|c.inymd[5]||0],c.each(new Array(3),function(a){c.hmsin[a].value=c.digit(c.timeVoid(f.times[a],a)?0|c.mins[a+3]:0|f.times[a])}),c[c.valid?"removeClass":"addClass"](h.ok,h[1])},c.festival=function(a,b){var c;switch(b){case"1.1":c="元旦";break;case"3.8":c="妇女";break;case"4.5":c="清明";break;case"5.1":c="劳动";break;case"6.1":c="儿童";break;case"9.10":c="教师";break;case"10.1":c="国庆"}c(a.innerHTML=c),c=null},c.viewYears=function(a){var b=c.query,d="";c.each(new Array(14),function(b){d+=7===b?"li "+(parseInt(h.year.value)===a?'class="'+h[2]+'"':"")+' y="'+a+'"'+a+"年/li":'li y="'+(a-7+b)+'"'+(a-7+b)+"年/li"}),b("#laydate_ys").innerHTML=d,c.each(b("#laydate_ys li"),function(a,b){"y"===c.checkVoid(b.getAttribute("y"))[0]?c.addClass(b,h[1]):c.on(b,"click",function(a){c.stopmp(a).reshow(),c.viewDate(0|this.getAttribute("y"),c.ymd[1],c.ymd[2])})})},c.initDate=function(){var d=(c.query,new Date),e=c.elem[h.elemv].match(/\d+/g)||[];e.length3(e=c.options.start.match(/\d+/g)||[],e.length3(e=[d.getFullYear(),d.getMonth()+1,d.getDate()])),c.inymd=e,c.viewDate(e[0],e[1]-1,e[2])},c.iswrite=function(){var a=c.query,b={time:a("#laydate_hms")};c.shde(b.time,!c.options.istime),c.shde(h.oclear,!("isclear"in c.options?c.options.isclear:1)),c.shde(h.otoday,!("istoday"in c.options?c.options.istoday:1)),c.shde(h.ok,!("issure"in c.options?c.options.issure:1))},c.orien=function(a,b){var d,e=c.elem.getBoundingClientRect();a.style.left=e.left+(b?0:c.scroll(1))+"px",d=e.bottom+a.offsetHeight/1.5=c.winarea()?e.bottom-1:e.topa.offsetHeight/1.5?e.top-a.offsetHeight+1:c.winarea()-a.offsetHeight,a.style.top=d+(b?0:c.scroll())+"px"},c.follow=function(a){c.options.fixed?(a.style.position="fixed",c.orien(a,1)):(a.style.position="absolute",c.orien(a))},
用这个:minDate,maxDate
jQuery('#holderCertiValidityDate').datepicker({
changeMonth: true,
changeYear: true,
showOn: 'button',
buttonImage: 'images/date.gif',
buttonImageOnly: true,
buttonText: '选择日期',
dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'],
monthNamesShort: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
dateFormat: 'yy-mm-dd',
minDate: '-0y -0m -0d',
yearRange: '1900:c+90'
});
//为“出生日期”添加单击函数
jQuery('#holderBirthday').datepicker({
changeMonth: true,
changeYear: true,
showOn: 'button',
buttonImage: 'images/date.gif',
buttonImageOnly: true,
buttonText: '选择日期',
dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'],
monthNamesShort: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
dateFormat: 'yy-mm-dd',
maxDate: '+0y +0m +0d',
yearRange: '1900:c+90'
});
日期对象可以使用系统的内置的构造函数来创建日期对象:
var d=new Date( );
d.getYear( ); //返回年不建议使用
d.getFullYear( ); //返回年,4位数,建议使用
d.getMonth( );//返回月份,其值为0-11;
d.getDate( );//返回返回日期对象中的一个月中的第几天
d.getDay( );//返回星期几中的某一天
d.getHours( );//返回日期对象的小时部分
d.getMinutes( );//返回分钟部分
d.getSeconds( );//返回秒钟
d.getMillSeconds( );//返回毫秒
d.getTime( );//返回时间戳
d.getTimezoneOffset( );//返回时区的时差数,单位是秒
希望对你有用.