JQuery UI Datepicker after selecting / changing month / year

I wanted to know how I can run a piece of code (attach a mouseenter event) for every day after a user selects a day or changes a month / year?

I tried to attach an event to these events

  • beforeShow
  • beforeShowDay
  • onChangeMonthYear
  • onSelect

On hover, I want to highlight the next day on the same line if it exists.

I am currently attaching a moouseenter / mouseleave event to all days after creating the date set by datepicker (which is inline).

I have simplified what I am doing in the JS script below. I need these events to work after selecting a date and after changing the month / year.

JS Fiddle: http://jsfiddle.net/MartinTale/Xx4GS/2/

$("div").datepicker({
    changeMonth: true,
    changeYear: true,
    inline: true,
    altField: "#datep"
});

$("tbody td:not(.ui-state-disabled, .active-calendar-cell)").mouseenter(function (e) {
    $(this).closest('td').next().find("a").addClass("hover-calendar-cell");    
    console.log('test');
});

$("tbody td:not(.ui-state-disabled)").mouseleave(function (e) {
    $("a.hover-calendar-cell").removeClass("hover-calendar-cell");
    console.log('test out');
});

Thanks in advance.

+4
3

.

http://jsfiddle.net/Xx4GS/3/

, ( td ).

setTimeout - , , jquery ui , , .

, onSelect .change, imo

console.log, , .

+8

jQuery datepicker onSelect onChangeMonthYear.

:

$("#datep").datepicker({
    changeMonth: true,
    changeYear: true,
    onSelect: function () {
        console.log('s');
    },
    onChangeMonthYear: function () {
        console.log('o');
    }
});

: http://jsfiddle.net/IrvinDominin/Xx4GS/

+13

There is an event called "onSelect" that has a date as its parameter. see this example:

$("#datePicker").datepicker({
    //the format
    dateFormat: "dd/mm/yy",
    //called when date is selected
    onSelect: function (date) {
        alert(date);
    }
});

Cou can find all the details in doc all-api: http://api.jqueryui.com/datepicker/#option-onSelect

+1
source

Source: https://habr.com/ru/post/1542629/


All Articles