Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
ootstrap-datepicker是一個開源、基于bootstrap的日期選擇器,內置60+種語言,基于bootstrap也使得選擇器非常美觀適合現代網站,功能強大,通過內置屬性、方法、事件組合配置可以滿足幾乎所有日期選擇需求,唯一遺憾的是不支持時間選擇,只能選擇年月日。
1、下載及初始化
https://github.com/uxsolutions/bootstrap-datepicker
下載完成后解壓,把dist文件夾中的所有文件放到項目中任意位置,引入下圖所示的文件即可。
然后在頁面body元素中創建一個容器,如下所示。
最后在id為sandbox-container的div元素中創建input元素,并運行以下代碼腳本,一個日期選擇器就創建好了。
2、特色展示
⑴組件選擇
⑵內聯選擇
⑶范圍選擇
⑷格式化日期
⑸最大最小日期
⑹選擇器開始界面
0:天(默認)
1:月
2:年
3:十年
4:世紀
⑺最大最小選擇精度
minViewMode最小、maxViewMode最大
0:天(最小默認)
1:月
2:年
3:十年
4:世紀(最大默認)
⑻今日、清除按鈕
⑼選擇器方向
auto:自動(默認)
top auto:向上自動
bottom auto:向下自動
auto left:自動向左
top left:左上
bottom left:左下
auto right:自動向右
top right:右上
bottom right:右下
⑽星期禁用、高亮
⑾多選、分隔符
⑿顯示第幾周
⒀選擇后自動關閉
⒁今日高亮
⒂選擇器界面顯示之前的回調函數
有世紀、十年、年、月、日五種類型,如下所示是(日的例子)
⒃禁用日期
⒄選中取消
⒅默認初始化視圖
⒆鍵盤操作
⒇星期幾作為一周的開始
在線演示網站:
https://uxsolutions.github.io/bootstrap-datepicker/
API文檔:
https://bootstrap-datepicker.readthedocs.io/en/latest/index.html
bootstrap datepicker內置8個事件(顯示、隱藏選擇器事件、清除日期選中事件和世紀、十年、年、月、日改變事件),內置20個方法(如銷毀、顯示、隱藏、更新選擇器方法等),支持鍵盤操作選擇日期,支持日期校驗等,功能豐富,希望以后能夠加入時間選擇。
有哪里寫得不好的地方請大家提出來,請輕噴,謝謝。 同時有什么與編程相關的好東西可以推舉給我,再次感謝!
網:
http://www.daterangepicker.com
關于參數匯總:
http://www.daterangepicker.com/#options
<link href="/css/daterangepicker.min.css?ver=0.6" rel="stylesheet" type="text/css" />
<script src="/js/date-time/moment.js?ver=0.6" type="text/javascript"></script>
<script src="/js/date-time/daterangepicker.zh-CN.js?ver=0.6" type="text/javascript"></script>
<script src="/js/date-time/daterangepicker.js?ver=0.6" type="text/javascript"></script>
<div class="input-group" style="width: 240px; margin-left: -5px;">
<input type="text" class=&qu·ot;form-control date-picker" id="dateTimeRange" value="" />
<span class="input-group-addon">
<i class="fa fa-calendar bigger-110"></i>
</span>
<input type="hidden" name="beginTime" id="beginTime" value="" />
<input type="hidden" name="endTime" id="endTime" value="" />
</div>
<a href="javascript:;" onclick="begin_end_time_clear();">清除</a>
<script type="text/javascript">
$(function() {
$('#dateTimeRange').daterangepicker({
applyClass : 'btn-sm btn-success',
cancelClass : 'btn-sm btn-default',
locale: {
applyLabel: '確認',
cancelLabel: '取消',
fromLabel : '起始時間',
toLabel : '結束時間',
customRangeLabel : '自定義',
firstDay : 1
},
ranges : {
//'最近1小時': [moment().subtract('hours',1), moment()],
'今日': [moment().startOf('day'), moment()],
'昨日': [moment().subtract('days', 1).startOf('day'), moment().subtract('days', 1).endOf('day')],
'最近7日': [moment().subtract('days', 6), moment()],
'最近30日': [moment().subtract('days', 29), moment()],
'本月': [moment().startOf("month"),moment().endOf("month")],
'上個月': [moment().subtract(1,"month").startOf("month"),moment().subtract(1,"month").endOf("month")]
},
opens : 'right', // 日期選擇框的彈出位置
separator : ' 至 ',
showWeekNumbers : true, // 是否顯示第幾周
//timePicker: true,
//timePickerIncrement : 10, // 時間的增量,單位為分鐘
//timePicker12Hour : false, // 是否使用12小時制來顯示時間
//maxDate : moment(), // 最大時間
format: 'YYYY-MM-DD'
}, function(start, end, label) { // 格式化日期顯示框
$('#beginTime').val(start.format('YYYY-MM-DD'));
$('#endTime').val(end.format('YYYY-MM-DD'));
})
.next().on('click', function(){
$(this).prev().focus();
});
});
/**
* 清除時間
*/
function begin_end_time_clear() {
$('#dateTimeRange').val('');
$('#beginTime').val('');
$('#endTime').val('');
}
</script>
單一時間顯示方法
1. 兼容IE8-11、360瀏覽器、chrome、firefox等主流瀏覽器,手機端也可使用;
2. 添加點擊前一周、后一周和高亮等功能。
1、初始化周歷原理:
首先獲取表示當前星期幾的數字currDay = d.getDay(),一般是0(周日)-6(周六);
然后把值取負數傳到方法creatWeeklyCalendar進行循環顯示一周時間;
Tips:方法calcTime是利用當前毫秒數+-循環數的毫秒數(someTime = d.getTime() + (24 * 60 * 60 * 1000) * num)算出這天的年月日。
for (var i = some, len = some + 7; i < len; i++) {
if (this.calcTime(i).month == currMonth && this.calcTime(i).date == currDate) {
html += '<li class="active"><a href="javascript:;" data-year="' + this.calcTime(i).year + '" title="' + this.calcTime(i).month + '月">' + this.calcTime(i).date + '</a></li>';
} else {
html += '<li><a href="javascript:;" data-year="' + this.calcTime(i).year + '" title="' + this.calcTime(i).month + '月">' + this.calcTime(i).date + '</a></li>';
}
}
最后把html輸出到頁面。
2、前一周和后一周原理:
首先利用點擊前一周和后一周按鈕,對計算數clickedTimes進行+-;
然后把clickedTimes新值傳到方法changeWeek;
最后執行this.creatWeeklyCalendar(-currDay - (7 * clickedTimes)),重新輸出新一周的數據。
3、最后把構造函數暴露window.WeeklyCalendar = WeeklyCalendar。
*請認真填寫需求信息,我們會在24小時內與您取得聯系。