html:

<link rel="stylesheet" type="text/css" href="css/jquery.date_input.pack.css">
......
<script type="text/javascript" src="js/jquery.date_input.pack.js"></script>
......
<script type="text/javascript">
$(function(){
$('.date_picker').date_input();
})
</script>
<body>
<input placeholder="日期" style="width:250px; line-height:23px;display:inline-block" type="text" class="date_picker" id="datatimeo">
</body>

jquery.date_input.pack.js:

DateInput = (function($) {
function DateInput(el, opts) {
if (typeof(opts) != "object") opts = {};
$.extend(this, DateInput.DEFAULT_OPTS, opts);
this.input = $(el);
this.bindMethodsToObj("show", "hide", "hideIfClickOutside", "keydownHandler", "selectDate");
this.build();
this.selectDate();
this.hide()
};
DateInput.DEFAULT_OPTS = {
month_names: ["一月份", "二月份", "三月份", "四月份", "五月份", "六月份", "七月份", "八月份", "九月份", "十月份", "十一月份", "十二月份"],
short_month_names: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"],
short_day_names: ["日", "一", "二", "三", "四", "五", "六"],
start_of_week: 1
};
DateInput.prototype = {
build: function() {
var monthNav = $('<p class="month_nav">' + '<span class="button prev" title="[Page-Up]">«</span>' + ' <span class="month_name"></span> ' + '<span class="button next" title="[Page-Down]">»</span>' + '</p>');
this.monthNameSpan = $(".month_name", monthNav);
$(".prev", monthNav).click(this.bindToObj(function() {
this.moveMonthBy( - 1)
}));
$(".next", monthNav).click(this.bindToObj(function() {
this.moveMonthBy(1)
}));
var yearNav = $('<p class="year_nav">' + '<span class="button prev" title="[Ctrl+Page-Up]">«</span>' + ' <span class="year_name"></span> ' + '<span class="button next" title="[Ctrl+Page-Down]">»</span>' + '</p>');
this.yearNameSpan = $(".year_name", yearNav);
$(".prev", yearNav).click(this.bindToObj(function() {
this.moveMonthBy( - 12)
}));
$(".next", yearNav).click(this.bindToObj(function() {
this.moveMonthBy(12)
}));
var nav = $('<div class="nav"></div>').append(monthNav, yearNav);
var tableShell = "<table><thead><tr>";
$(this.adjustDays(this.short_day_names)).each(function() {
tableShell += "<th>" + this + "</th>"
});
tableShell += "</tr></thead><tbody></tbody></table>";
this.dateSelector = this.rootLayers = $('<div class="date_selector"></div>').append(nav, tableShell).insertAfter(this.input);
if ($.browser.msie && $.browser.version < 7) {
this.ieframe = $('<iframe class="date_selector_ieframe" frameborder="0" src="#"></iframe>').insertBefore(this.dateSelector);
this.rootLayers = this.rootLayers.add(this.ieframe);
$(".button", nav).mouseover(function() {
$(this).addClass("hover")
});
$(".button", nav).mouseout(function() {
$(this).removeClass("hover")
})
};
this.tbody = $("tbody", this.dateSelector);
this.input.change(this.bindToObj(function() {
this.selectDate()
}));
this.selectDate()
},
selectMonth: function(date) {
var newMonth = new Date(date.getFullYear(), date.getMonth(), 1);
if (!this.currentMonth || !(this.currentMonth.getFullYear() == newMonth.getFullYear() && this.currentMonth.getMonth() == newMonth.getMonth())) {
this.currentMonth = newMonth;
var rangeStart = this.rangeStart(date),
rangeEnd = this.rangeEnd(date);
var numDays = this.daysBetween(rangeStart, rangeEnd);
var dayCells = "";
for (var i = 0; i <= numDays; i++) {
var currentDay = new Date(rangeStart.getFullYear(), rangeStart.getMonth(), rangeStart.getDate() + i, 12, 00);
if (this.isFirstDayOfWeek(currentDay)) dayCells += "<tr>";
if (currentDay.getMonth() == date.getMonth()) {
dayCells += '<td class="selectable_day" date="' + this.dateToString(currentDay) + '">' + currentDay.getDate() + '</td>'
} else {
dayCells += '<td class="unselected_month" date="' + this.dateToString(currentDay) + '">' + currentDay.getDate() + '</td>'
};
if (this.isLastDayOfWeek(currentDay)) dayCells += "</tr>"
};
this.tbody.empty().append(dayCells);
this.monthNameSpan.empty().append(this.monthName(date));
this.yearNameSpan.empty().append(this.currentMonth.getFullYear());
$(".selectable_day", this.tbody).click(this.bindToObj(function(event) {
this.changeInput($(event.target).attr("date"))
}));
$("td[date=" + this.dateToString(new Date()) + "]", this.tbody).addClass("today");
$("td.selectable_day", this.tbody).mouseover(function() {
$(this).addClass("hover")
});
$("td.selectable_day", this.tbody).mouseout(function() {
$(this).removeClass("hover")
})
};
$('.selected', this.tbody).removeClass("selected");
$('td[date=' + this.selectedDateString + ']', this.tbody).addClass("selected")
},
selectDate: function(date) {
if (typeof(date) == "undefined") {
date = this.stringToDate(this.input.val())
};
if (!date) date = new Date();
this.selectedDate = date;
this.selectedDateString = this.dateToString(this.selectedDate);
this.selectMonth(this.selectedDate)
},
changeInput: function(dateString) {
this.input.val(dateString).change();
this.hide()
},
show: function() {
this.rootLayers.css("display", "block");
$([window, document.body]).click(this.hideIfClickOutside);
this.input.unbind("focus", this.show);
$(document.body).keydown(this.keydownHandler);
this.setPosition()
},
hide: function() {
this.rootLayers.css("display", "none");
$([window, document.body]).unbind("click", this.hideIfClickOutside);
this.input.focus(this.show);
$(document.body).unbind("keydown", this.keydownHandler)
},
hideIfClickOutside: function(event) {
if (event.target != this.input[0] && !this.insideSelector(event)) {
this.hide()
}
},
insideSelector: function(event) {
var offset = this.dateSelector.position();
offset.right = offset.left + this.dateSelector.outerWidth();
offset.bottom = offset.top + this.dateSelector.outerHeight();
return event.pageY < offset.bottom && event.pageY > offset.top && event.pageX < offset.right && event.pageX > offset.left
},
keydownHandler: function(event) {
switch (event.keyCode) {
case 9:
case 27:
this.hide();
return;
break;
case 13:
this.changeInput(this.selectedDateString);
break;
case 33:
this.moveDateMonthBy(event.ctrlKey ? -12 : -1);
break;
case 34:
this.moveDateMonthBy(event.ctrlKey ? 12 : 1);
break;
case 38:
this.moveDateBy( - 7);
break;
case 40:
this.moveDateBy(7);
break;
case 37:
this.moveDateBy( - 1);
break;
case 39:
this.moveDateBy(1);
break;
default:
return
}
event.preventDefault()
},
stringToDate: function(string) {
var matches;
if (matches = string.match(/^(\d{1,2}) ([^\s]+) (\d{4,4})$/)) {
return new Date(matches[3], this.shortMonthNum(matches[2]), matches[1], 12, 00)
} else {
return null
}
},
dateToString: function(date) {
return date.getFullYear()+"-"+this.short_month_names[date.getMonth()]+"-" +date.getDate()
},
setPosition: function() {
var offset = this.input.offset();
this.rootLayers.css({
top: offset.top + this.input.outerHeight(),
left: offset.left
});
if (this.ieframe) {
this.ieframe.css({
width: this.dateSelector.outerWidth(),
height: this.dateSelector.outerHeight()
})
}
},
moveDateBy: function(amount) {
var newDate = new Date(this.selectedDate.getFullYear(), this.selectedDate.getMonth(), this.selectedDate.getDate() + amount);
this.selectDate(newDate)
},
moveDateMonthBy: function(amount) {
var newDate = new Date(this.selectedDate.getFullYear(), this.selectedDate.getMonth() + amount, this.selectedDate.getDate());
if (newDate.getMonth() == this.selectedDate.getMonth() + amount + 1) {
newDate.setDate(0)
};
this.selectDate(newDate)
},
moveMonthBy: function(amount) {
var newMonth = new Date(this.currentMonth.getFullYear(), this.currentMonth.getMonth() + amount, this.currentMonth.getDate());
this.selectMonth(newMonth)
},
monthName: function(date) {
return this.month_names[date.getMonth()]
},
bindToObj: function(fn) {
var self = this;
return function() {
return fn.apply(self, arguments)
}
},
bindMethodsToObj: function() {
for (var i = 0; i < arguments.length; i++) {
this[arguments[i]] = this.bindToObj(this[arguments[i]])
}
},
indexFor: function(array, value) {
for (var i = 0; i < array.length; i++) {
if (value == array[i]) return i
}
},
monthNum: function(month_name) {
return this.indexFor(this.month_names, month_name)
},
shortMonthNum: function(month_name) {
return this.indexFor(this.short_month_names, month_name)
},
shortDayNum: function(day_name) {
return this.indexFor(this.short_day_names, day_name)
},
daysBetween: function(start, end) {
start = Date.UTC(start.getFullYear(), start.getMonth(), start.getDate());
end = Date.UTC(end.getFullYear(), end.getMonth(), end.getDate());
return (end - start) / 86400000
},
changeDayTo: function(dayOfWeek, date, direction) {
var difference = direction * (Math.abs(date.getDay() - dayOfWeek - (direction * 7)) % 7);
return new Date(date.getFullYear(), date.getMonth(), date.getDate() + difference)
},
rangeStart: function(date) {
return this.changeDayTo(this.start_of_week, new Date(date.getFullYear(), date.getMonth()), -1)
},
rangeEnd: function(date) {
return this.changeDayTo((this.start_of_week - 1) % 7, new Date(date.getFullYear(), date.getMonth() + 1, 0), 1)
},
isFirstDayOfWeek: function(date) {
return date.getDay() == this.start_of_week
},
isLastDayOfWeek: function(date) {
return date.getDay() == (this.start_of_week - 1) % 7
},
adjustDays: function(days) {
var newDays = [];
for (var i = 0; i < days.length; i++) {
newDays[i] = days[(i + this.start_of_week) % 7]
};
return newDays
}
};
$.fn.date_input = function(opts) {
return this.each(function() {
new DateInput(this, opts)
})
};
$.date_input = {
initialize: function(opts) {
$("input.date_input").date_input(opts)
}
};
return DateInput
})(jQuery); jQuery.browser={};(function(){jQuery.browser.msie=false; jQuery.browser.version=0;if(navigator.userAgent.match(/MSIE ([0-9]+)./)){ jQuery.browser.msie=true;jQuery.browser.version=RegExp.$1;}})();

jquery.date_input.pack.css:

.date_selector, .date_selector *{width: auto;height: auto;border: none;background: none;margin:;padding:;text-align: left;text-decoration: none;}

.date_selector{background:#fbfbfb;border: 1px solid #ccc;padding: 10px;margin:;margin-top:-1px;position: absolute;z-index:;display:none;border-radius: 3px;box-shadow: 0 0 5px #aaa;box-shadow:0 2px 2px #ccc;}

.date_selector_ieframe{position: absolute;z-index:;display: none;}

.date_selector .nav{width: 17.5em;}

.date_selector .nav p{clear: none;}

.date_selector .month_nav, .date_selector .year_nav{margin: 0 0 3px 0;padding:;display: block;position: relative;text-align: center;}

.date_selector .month_nav{float: left;width: 55%;}

.date_selector .year_nav{float: right;width: 42%;margin-right: -8px;}

.date_selector .month_name, .date_selector .year_name{font-weight: bold;line-height: 20px;}

.date_selector .button{display: block;position: absolute;top:;width:18px;height:18px;line-height:16px;font-weight:bold;color:#5985c7;text-align: center;font-size:12px;overflow:hidden;border: 1px solid #ccc;border-radius:2px;}

.date_selector .button:hover, .date_selector .button.hover{background:#5985c7;color: #fff;cursor: pointer;border-color:#3a930d;}

.date_selector .prev{left:;}

.date_selector .next{right:;}

.date_selector table{border-spacing:;border-collapse: collapse;clear: both;margin:; width:220px;}

.date_selector th, .date_selector td{width: 2.5em;height: 2em;padding: 0 !important;text-align: center !important;color: #666;font-weight: normal;}

.date_selector th{font-size: 12px;}

.date_selector td{border:1px solid #f1f1f1;line-height: 2em;text-align: center;white-space: nowrap;color:#5985c7;background: #fff;}

.date_selector td.today{background: #eee;}

.date_selector td.unselected_month{color: #ccc;}

.date_selector td.selectable_day{cursor: pointer;}

.date_selector td.selected{background:#2b579a;color: #fff;font-weight: bold;}

.date_selector td.selectable_day:hover, .date_selector td.selectable_day.hover{background:#5985c7;color: #fff;}

简单日历插件jquery.date_input.pack的更多相关文章

  1. 【UI插件】开发一个简单日历插件(上)

    前言 最近开始整理我们的单页应用框架了,虽然可能比不上MVVM模式的开发效率,也可能没有Backbone框架模块清晰,但是好歹也是自己开发出来 而且也用于了这么多频道的东西,如果没有总结,没有整理,没 ...

  2. jQuery简单日历插件版

    先来看demo:http://codepen.io/jonechen/pen/xOgZMz 插件代码: ; (function($) { var Calendar = function(ele, op ...

  3. 10个漂亮的jQuery日历插件下载【转载】

    10个漂亮的jQuery日历插件下载 2013-08-07 标签:jQuery日历插件jQuery日历jQuery插件   日期是非常重要的,随时随地.微薄或网站的日期选取器日历必须在那里.您可以使用 ...

  4. jquery双日历日期选择器bootstrap-daterangepicker日历插件

    这个插件既可以作为双日历也可以作为单日历插件(jquery的插件在jquery插件库中http://www.jq22.com/下载很方便,在CSDN下载真麻烦) 引用 <meta http-eq ...

  5. jQuery插件之——简单日历

    最近在研究js插件的开发,以前看大神们,对插件都是信手拈来,随便玩弄,感觉自己要是达到那种水平就好了,就开始自己研究插件开发了.研究了一段时间之后,就开始写了自己的第一个日历插件,由于是初学插件开发, ...

  6. jQuery插件实战之fullcalendar(日历插件)Demo

    jQuery的插件许多,应用的场景也很丰富,今天我这里给大家介绍一款很有用的日历页面开发插件 - fullcalendar,眼下最新版本号是1.5.1,使用这款插件可以高速帮助你高速编程实现基于web ...

  7. 给开发者准备的 10 款最好的 jQuery 日历插件[转]

    这篇文章介绍的是 10 款最棒而且又很有用的 jQuery 日历插件,允许开发者们把这些漂亮的日历插件结合到自己的网站中.这些日历插件易用性都很强,轻轻松松的就可以把漂亮的日历插件装饰到你的网站了.希 ...

  8. 基于jQuery日历插件制作日历

    这篇文章主要介绍了基于jQuery日历插件制作日历的相关资料,需要的朋友可以参考下 来看下最终效果图吧: 是长得丑了一点,不要吐槽我-.- 首先来说说这个日历主要的制作逻辑吧: ·一个月份最多有31天 ...

  9. 被逼着写的jquery工作日管理日历插件

    因为工作原因,在我刚进入新公司之后,立马要求让我做一个jquery的插件demo.我的天,我面试的可是.net工程师啊.虽然以前接触过js,jquery,但也只是接触过一丢丢啊,没办法,只好硬着头皮上 ...

随机推荐

  1. schema.path方法

    var sampleSchema = new Schema({ name: { type: String, required: true } }); console.log(sampleSchema. ...

  2. CCTargetedAction

    改变动作执行对象CCTargetedAction 通常默认的动作执行对象是调用runAction的对象,而CCTargetedAction可以改变动作执行对象. CCTargetedAction* t ...

  3. canvas.drawBitmap(bitmap, src, dst, paint)

    // GameView.drawImage(canvas, mBitDestTop, miDTX, mBitQQ.getHeight(), mBitDestTop.getWidth(), mBitDe ...

  4. chrome浏览器的scrollTop问题

    使用zepto里面的scrollTop()方法是没用哒~~~ chrome浏览器: document.body.scrollTop = 一个数值 其它浏览器: document.documentEle ...

  5. [转贴]Cocos2d-x3.2与OpenGL渲染总结(一)Cocos2d-x3.2的渲染流程

    看了opengles有一段时间了,算是了解了一下下.然后,就在基本要决定还是回归cocos2dx 3.2的,看了这篇好文章,欣喜转之~ 推荐看原帖: Cocos2d-x3.2与OpenGL渲染总结(一 ...

  6. 解决老是提示找不到Mapper文件无法执行定义的方法问题!

    尼玛,被mybatis的*Mapper.xml文件害惨了!整整两天都在围绕这个问题转圈! 先看问题长啥样吧!下面是通过逆向工程生成的Mapper.xml文件,包路径什么的都没有错! 但是每次调用Map ...

  7. LeetCode: Merge Intervals 解题报告

    Merge IntervalsGiven a collection of intervals, merge all overlapping intervals. For example,Given [ ...

  8. Cannon

    Description In Chinese Chess, there is one kind of powerful chessmen called Cannon. It can move hori ...

  9. jQuery 初识

    现在的项目中,用纯js的已经很少了,基本都是找这些好用的库,毕竟功能强大,学习简单,而且插件多. 今天就来学习下. 学习一个东西,就要先用安装入手. 这里我就直接从别的地方引入jquery库了, 引入 ...

  10. JS地毯式学习一

    1.<noscript> 现代浏览器都对JavaScript进行了支持,一般是在用户的浏览器禁用了脚本的情况下才会显示<noscript>的内容. 包含在<noscrip ...