Datepicker onSelect Not Firing

主宰稳场 提交于 2019-12-07 08:12:36

问题


I have a date picker but onClose and onSelect will not fire. The code is in document.ready so i know its initialized.

$('#DateRangeTo').datepicker({
    beforeShow: function (input, inst) {
        inst.dpDiv.css({ marginTop: -input.offsetHeight + 'px', marginLeft: input.offsetWidth + 'px' });
    },
    format: "dd/mm/yyyy",
    startView: 1,
    //daysOfWeekDisabled: "3,4",
    autoclose: true,
    todayHighlight: true,
    //onClose: function (dateText, inst) { alert("here"); }
    onSelect: function (dateText, inst)
    {
        alert("Working");
    },
    onClose: function (date) {
        var dt = new Date(date);
        alert(dt.getMonth());
    }
});

回答1:


Must this code work when select a date:

$("#datepicker").datepicker({
dateFormat: 'dd/mm/yy'}).on("changeDate", function (e) {
alert("Working");});



回答2:


Some of the Options you are using are not available in datepicker see http://api.jqueryui.com/datepicker/

And also you are missing $(function () {}); See below updated code

$(function () {
            $('#DateRangeTo').datepicker({
                beforeShow: function (input, inst) {
                    inst.dpDiv.css({ marginTop: -input.offsetHeight + 'px', marginLeft: input.offsetWidth + 'px' });
                },
                dateFormat: "dd/mm/yyyy",
                //startView: 1,
                //daysOfWeekDisabled: "3,4",
                //autoclose: true,
                //todayHighlight: true,
                //onClose: function (dateText, inst) { alert("here"); }
                onSelect: function (dateText, inst) {
                    alert("Working");
                },
                onClose: function (date) {
                    var dt = new Date(date);
                    alert(dt.getMonth());
                }
            });
        });

If still not worked then check for javascript errors in your error console.




回答3:


The datepicker doesn't trigger the onSelect if there are multiple inputs with the same ID. You shouldn't have multiple elements with the same ID to begin with but the datepicker will show and appear to work and show up. Even some of the other methods like onClose do work but the final onSelect will not



来源:https://stackoverflow.com/questions/21754196/datepicker-onselect-not-firing

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