$(document).ready(function() {
$('#reservation').daterangepicker({
format : 'YYYY-MM-DD',
separator : '~',
locale : {
applyLabel : '确定',
cancelLabel : '清空',
fromLabel : '起始时间',
toLabel : '结束时间',
customRangeLabel : '自定义',
daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月' ],
firstDay : 1
}
});
//点击清空触发
$('#reservation').on('cancel.daterangepicker', function(ev, picker) {
$('#reservation').val('');
});
});
$('#reservation').daterangepicker({
format : 'YYYY-MM-DD',
separator : '~',
locale : {
applyLabel : '确定',
cancelLabel : '清空',
fromLabel : '起始时间',
toLabel : '结束时间',
customRangeLabel : '自定义',
daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月' ],
firstDay : 1
}
});
//点击清空触发
$('#reservation').on('cancel.daterangepicker', function(ev, picker) {
$('#reservation').val('');
});
});
本文介绍了一个使用 jQuery 初始化日期选择器的方法,并实现了日期范围选择与清空功能。通过自定义设置如格式、标签文本等,增强了用户体验。同时,还提供了点击‘清空’按钮后重置输入框值的功能。

被折叠的 条评论
为什么被折叠?



