html响应式日历,百行js代码实现一个内联响应式日历jquery插件

(function($){varmonths=["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"];vartabletpl='

'+' {0} '+' {1}
'+'今天'+'
';varformatbody=function(date,curdate){

date=newDate(date.getFullYear(),date.getMonth()+1,0);vardays=date.getDate();varstr="";varprelens=[6,0,1,2,3,4,5];//如果1号不是礼拜一跳过的单元格varcurday=1;

date=newDate(date.getFullYear(),date.getMonth(),1)varpreday=prelens[date.getDay()];

str+='

';while(preday--)str+='';varweekday;varcurdateday=newDate(curdate.getFullYear(),curdate.getMonth(),curdate.getDate());while(curday<=days){

date=newDate(date.getFullYear(),date.getMonth(),curday);

str+=(date.getTime()===curdateday.getTime()?'

':'');

str+=curday+'

';

weekday=date.getDay();if(weekday===0)str+='

';++curday;

}if(weekday===0)returnstr.substring(0,str.length-4);elsereturnstr;

}varformathtml=function(date,curdate){varlist=[""+date.getFullYear(),months[date.getMonth()],formatbody(date,curdate)];returntabletpl.replace(/\{(\d)\}/g,function(u,i){returnlist[+i];

});

}

$.fn.timePicker=function(options) {vardateNow=newDate();vardefaults={

curdate:dateNow,

showdate:dateNow,        callback:function(){}

};varsettings=$.extend({}, defaults, options);returnthis.each(function() {varcur=$(this);varreshow=function(){

cur.empty();

cur.append(formathtml(settings.showdate,settings.curdate));

}varchangevalue=function(year,plus){vary=settings.showdate.getFullYear();varm=settings.showdate.getMonth();if(year)y+=plus?1:-1;else{

m+=plus?1:-1;if(m>11){y+=1;m=0;}if(m<0){y-=1;m=11;}

}

settings.showdate=newDate(y,m,settings.showdate.getDate());

reshow();

}vartoday=function(){

settings.curdate=settings.showdate=newDate();

reshow();

}vartdclick=function(){varv=$(this).text();if(v.length<1)return;varnewDate=newDate(settings.showdate.getFullYear(),settings.showdate.getMonth(),+v);

settings.callback(newDate);//仅当点了单元格中日期才回调并设置选中日期

settings.curdate=settings.showdate=newDate;

reshow();

}

reshow();

cur.off("click");

cur.on("click",".FEdatepicker div button",function(){varindex=$(this).index();

changevalue(index<2?true:false,index%2?true:false);

});

cur.on("click",".FEdatepicker button:eq(4)",today);

cur.on("click",".FEdatepicker table tbody td",tdclick);

});

};

})(jQuery);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值