input id="db"/
目前创新互联已为上千余家的企业提供了网站建设、域名、雅安服务器托管、绵阳服务器托管、企业网站设计、竹溪网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
script
$(function () {
$('#db').datebox({
onShowPanel: function () {//显示日趋选择对象后再触发弹出月份层的事件,初始化时没有生成月份层
span.trigger('click'); //触发click事件弹出月份层
if (!tds) setTimeout(function () {//延时触发获取月份对象,因为上面的事件触发和对象生成有时间间隔
tds = p.find('div.calendar-menu-month-inner td');
tds.click(function (e) {
e.stopPropagation(); //禁止冒泡执行easyui给月份绑定的事件
var year = /\d{4}/.exec(span.html())[0]//得到年份
, month = parseInt($(this).attr('abbr'), 10) + 1; //月份
$('#db').datebox('hidePanel')//隐藏日期对象
.datebox('setValue', year + '-' + month); //设置日期的值
});
}, 0)
},
parser: function (s) {//配置parser,返回选择的日期
if (!s) return new Date();
var arr = s.split('-');
return new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, 1);
},
formatter: function (d) { return d.getFullYear() + '-' + d.getMonth(); }//配置formatter,只返回年月
});
var p = $('#db').datebox('panel'), //日期选择对象
tds = false, //日期选择对象中月份
span = p.find('span.calendar-text'); //显示月份层的触发控件
});
/script
easyui 1.4.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( );//返回时区的时差数,单位是秒
希望对你有用.
复制代码
代码如下:
$("#regDate").datepicker(
{
showMonthAfterYear:
true,
//
月在年之后显示
changeMonth:
true,
//
允许选择月份
changeYear:
true,
//
允许选择年份
dateFormat:'yy-mm-dd',
//
设置日期格式
closeText:'关闭',
//
只有showButtonPanel:
true才会显示出来
duration:
'fast',
showAnim:'fadeIn',
showOn:'button',
//
在输入框旁边显示按钮触发,默认为:focus。还可以设置为both
buttonImage:
'images/commons/calendar.gif',
//
按钮图标
buttonImageOnly:
true,
//
不把图标显示在按钮上,即去掉按钮
buttonText:'选择日期',
showButtonPanel:
true,
showOtherMonths:
true,
//appendText:
'(yyyy-mm-dd)',
});
网络不好。使用jquery日期控件设置日期时,会自动连接网络进行查找日期,网络不好就会出现只有每月的1号可以选的现象,只要连接较好的网络即可解决。