jquery.datepair是一个轻量级的jquery插件,智能选择日期和时间范围,灵感来自于谷歌日历。datepair将保持开始和结束日期/时间同步,并可以根据用户的操作设置默认值。该插件不提供任何ui小部件; 它预先配置工作的jquery-timepicker和引导datepicker的,但你可以使用它与任何日期选择器或timepicker。
实例代码
<p id="basicExample">
<input type="text" class="date start" />
<input type="text" class="time start" /> to <input type="text" class="time end" />
<input type="text" class="date end" /></p><script type="text/javascript" src="bootstrap-datepicker.js"></script><script type="text/javascript" src="jquery.timepicker.js"></script><script type="text/javascript" src="jquery.datepair.js"></script><script>
// initialize input widgets first
$('#basicExample .time').timepicker({ 'showDuration': true, 'timeFormat': 'g:ia'
}); $('#basicExample .date').datepicker({ 'format': 'm/d/yyyy', 'autoclose': true
}); // initialize datepair
$('#basicExample').datepair();</script>// HTML not shown for brevity
$('#timeOnlyExample .time').timepicker({
'showDuration': true,
'timeFormat': 'g:ia'
});
$('#timeOnlyExample').datepair();
$('#dateOnlyExample .date').datepicker({
'format': 'yyyy-m-d',
'autoclose': true
});
$('#dateOnlyExample').datepair();// HTML not shown for brevity
$('#defaultDeltaExample').datepair({
'defaultDateDelta': 1, // days
'defaultTimeDelta': 7200000 // milliseconds
});<script type="text/javascript" src="pikaday.js"></script><script type="text/javascript" src="jquery.ptTimeSelect.js"></script><script type="text/javascript" src="moment.js"></script><script>
// initialize input widgets
// ptTimeSelect doesn't trigger change event by default
$('#alternateUiWidgetsExample .time').ptTimeSelect({ 'onClose': function($self) {
$self.trigger('change');
}
}); $('#alternateUiWidgetsExample .date').pikaday(); var TIMEFORMAT = 'h:mm a'; $('#alternateUiWidgetsExample').datepair({ parseTime: function($input){ // use moment.js to parse time
var m = moment($input.val(), TIMEFORMAT); return m.toDate();
}, updateTime: function($input, dateObj){ var m = moment(dateObj);
$input.val(m.format(TIMEFORMAT));
}, parseDate: function($input){ var picker = $input.data('pikaday'); return picker.getDate();
}, updateDate: function($input, dateObj){ var picker = $input.data('pikaday'); return picker.setDate(dateObj);
}
});</script>// HTML not shown for brevity
// initialize input widgets first
$('#eventsExample .time').timepicker({
'showDuration': true,
'timeFormat': 'g:ia'
});
$('#eventsExample .date').datepicker({
'format': 'm/d/yyyy',
'autoclose': true
});
$('#eventsExample').datepair().on('rangeSelected', function(){
$('#eventsExampleStatus').text('Valid range selected');
}).on('rangeIncomplete', function(){
$('#eventsExampleStatus').text('Incomplete range');
}).on('rangeError', function(){
$('#eventsExampleStatus').text('Invalid range');
});
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号