JQuery Datepicker, can't trigger onSelect event manually!

前端 未结 9 1035
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-05 00:00

I am using jquery\'s datepicker where a list of items is populated from an ajax call whenever a date is picked from an inline datepicker object. The script works perfect exc

9条回答
  •  既然无缘
    2021-01-05 00:27

    This is how I got round the same problem. Simply register an event with the code you want to call, then call that event from the onSelect method inside datepicker and then call that same event any other time you want.

    $(document).ready(function(){
    
        // Onselect event registration
        $("#date_calendar").bind("datepickeronSelect", function(){
    
            alert("onSelect called!");
    
        })
    
        //create date pickers
        $("#date_calendar").datepicker(
        { 
            changeMonth: true,
            changeYear: true,
            dateFormat: 'yy-mm-dd',
            defaultDate: $.datepicker.parseDate("y-m-d", $('#date').val()),
            onSelect: function(dateText, inst)
            {
                $("#date_calendar").trigger("datepickeronSelect");
            }
        }).disableSelection().trigger("datepickeronSelect");
    });
    

提交回复
热议问题