日期选择器允许无效日期
Datapicker allow invalid dates
当用户不知道确切日期时,我需要允许像“99/99/9999”这样的日期,我该如何实现?
$('#date').datepicker({
language: "pt-BR",
autoclose: true,
format: 'dd/mm/yyyy',
todayHighlight: true
})
使用此代码,“99/99/9999”将转换为“07/06/9999”。
您可以将选项 constrainInput
设置为 false :
$('#date').datepicker({
language: "pt-BR",
autoclose: true,
format: 'dd/mm/yyyy',
todayHighlight: true,
constrainInput: false
})
希望对您有所帮助。
你可以使用 forceParse
option setting its value to false
. As the documentation 说:
Whether or not to force parsing of the input value when the picker is closed. That is, when an invalid date is left in the input field by the user, the picker will forcibly parse that value, and set the input’s value to the new, valid date, conforming to the given format.
这是一个活生生的例子:
$('input.datum').datepicker({
format: 'dd.mm.yyyy',
language: 'de',
weekStart: 1,
autoclose: true,
assumeNearbyYear: true,
forceParse: false
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker3.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/locales/bootstrap-datepicker.de.min.js"></script>
<form action="#" method="post">
<label>Date:</label>
<input class="datum" type="text" name="vondatum" required>
<input type="submit" value="save">
</form>
当用户不知道确切日期时,我需要允许像“99/99/9999”这样的日期,我该如何实现?
$('#date').datepicker({
language: "pt-BR",
autoclose: true,
format: 'dd/mm/yyyy',
todayHighlight: true
})
使用此代码,“99/99/9999”将转换为“07/06/9999”。
您可以将选项 constrainInput
设置为 false :
$('#date').datepicker({
language: "pt-BR",
autoclose: true,
format: 'dd/mm/yyyy',
todayHighlight: true,
constrainInput: false
})
希望对您有所帮助。
你可以使用 forceParse
option setting its value to false
. As the documentation 说:
Whether or not to force parsing of the input value when the picker is closed. That is, when an invalid date is left in the input field by the user, the picker will forcibly parse that value, and set the input’s value to the new, valid date, conforming to the given format.
这是一个活生生的例子:
$('input.datum').datepicker({
format: 'dd.mm.yyyy',
language: 'de',
weekStart: 1,
autoclose: true,
assumeNearbyYear: true,
forceParse: false
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker3.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/locales/bootstrap-datepicker.de.min.js"></script>
<form action="#" method="post">
<label>Date:</label>
<input class="datum" type="text" name="vondatum" required>
<input type="submit" value="save">
</form>