源码:http://github.com/ChiperSoft/Kalendae
demo:http://www.html5tricks.com/demo/Kalendae/index.html
Kalendae是一款完全基于JavaScript的日期选择控件和日历组件,值得一提的是,Kalendae并没有依赖任何第三方的JS脚本库,而是用原生的JavaScript实现了如此功能强大的日期选择控件。
导入对应的javascript和CSS:
<span style="font-size:14px;"><link rel="stylesheet" href="build/kalendae.css" type="text/css" charset="utf-8"> <script src="build/kalendae.js" type="text/javascript" charset="utf-8"></script> </span>
针对不同的使用环境设置,如下:
<span style="font-size:14px;">new Kalendae(document.body, { months:1, mode:'single', selected:Kalendae.moment().subtract({M:1}) }); new Kalendae({ attachTo:document.body, months:2, mode:'single', selected:Kalendae.moment().subtract({M:1}) }); new Kalendae({ attachTo:document.body, months:3, mode:'single', selected:Kalendae.moment().subtract({M:1}) });</span>
<span style="font-size:14px;">new Kalendae(document.body, { months:1, mode:'range', selected:[Kalendae.moment().subtract({M:1}), Kalendae.moment().add({M:1})] }); new Kalendae({ attachTo:document.body, months:2, mode:'range', selected:[Kalendae.moment().subtract({M:1}), Kalendae.moment().add({M:1})] }); new Kalendae({ attachTo:document.body, months:3, mode:'range', selected:[Kalendae.moment().subtract({M:1}), Kalendae.moment().add({M:1})] });</span>
<span style="font-size:14px;">new Kalendae(document.body, { months:1, mode:'multiple', selected:[Kalendae.moment().subtract({M:1}), Kalendae.moment().add({M:1})] }); new Kalendae({ attachTo:document.body, months:2, mode:'multiple', selected:[Kalendae.moment().subtract({M:1}), Kalendae.moment().add({M:1})] }); new Kalendae({ attachTo:document.body, months:3, mode:'multiple', selected:[Kalendae.moment().subtract({M:1}), Kalendae.moment().add({M:1})] });</span>
<span style="font-size:14px;">//direction new Kalendae(document.body, { months:3, direction:'future' }); //direction new Kalendae(document.body, { months:3, direction:'past' }); //blackout new Kalendae(document.body, { blackout: function (date) { return Kalendae.moment(date).date() % 2; //blackout every other day } }); //blackout AND direction new Kalendae(document.body, { direction:'future', blackout: function (date) { return [1,0,0,0,0,0,1][Kalendae.moment(date).day()]; //blackout weekends } });</span>
更多javascript请参考Demo。
指定HTML元素,只需要指定需要生成的元素的class为auto-kal即可。
<div class="auto-kal"></div>
或者使用input来生成弹出的日期选择
<input type="text" class="auto-kal">
缺省不需要jQuery的支持,但是提供一个jQuery插件,如果你使用jQuery,可以使用如下方式来生成一个kalendae日期选择:
$(selector).kalendae(options);