我需要这样做:只允许daterangepicker文本输入来接受正确的日期(例如:当你选择了13-01-2020
,然后点击输入并开始键入18
时,你会得到18-01-2020 instead of 1813-01-2020
,当然不允许非数字……我希望这一点很清楚(。
Js Fiddle is here: https://jsfiddle.net/20z5qym9/
到目前为止我的自定义代码:
<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
<script>
$(function() {
$('input[name="data_u"]').daterangepicker({
singleDatePicker: true,
showDropdowns: true,
oneTap: true,
minYear: 1901,
maxYear: 2022,
"locale": {
"format": "DD-MM-YYYY",
"separator": " - ",
"applyLabel": "OK",
"cancelLabel": "Leave",
"fromLabel": "From",
"toLabel": "To",
"customRangeLabel": "Custom",
//custimizable list od days
"daysOfWeek": [
"Pn",
"Wt",
"Śr",
"Czw",
"Pt",
"So",
"Nd"
],
//and months
"monthNames": [
"Styczeń",
"Luty",
"Marzec",
"Kwiecień",
"Maj",
"Czerwiec",
"Lipiec",
"Sierpień",
"Wrzesień",
"Październik",
"Listopad",
"Grudzień"
],
"firstDay": 0
}
}
, function(start, end, label) {
//callback when you choose month, but I would need to have callback on every key pressed I guess
});
});
</script>
<input type='date' />
我现在就是这样做的。工作正常,但并不完美(本地化设置由浏览器控制,这意味着用户,也意味着他可以有不同的日期格式、日期选择器行为等(。
有趣的是,我没有意识到,浏览器从一段时间以来就有这种类型的输入。