问题
Onselect is not working on my date picker.
Thus it gives me NaN
as a return value in other functions.
Does anybody have an idea or a solution for this?
I have no clue.
$(document).ready(function () {
var age = "";
$('#dob').datepicker({
onSelect: function (value, ui) {
var today = new Date();
age = (today.getFullYear() - ui.selectedYear) * 12;
age -= ui.selectedMonth;
age += today.getMonth();
$('#age').val(parseFloat(age));
},
changeMonth: true,
changeYear: true
})
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<label for="dob">DOB:</label>
<input id="dob" />
<br />
<label for="age">Age:</label>
<input id="age" readonly />
来源:https://stackoverflow.com/questions/59978417/onselect-function-is-not-working-on-my-date-picker