onselect function is not working on my date picker

会有一股神秘感。 提交于 2021-01-29 22:09:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!