How to add onChange event to dropdown boxes of JQuery.DatePicker

江枫思渺然 提交于 2019-12-08 09:43:41

问题


I have the following situation: Fiddle

What I want, is to add an onChange event to the dropdown boxes of the datepicker so that I will be able to capture the selected month/year in the text box above as a new value is selected from the calendar.

PS: Inspecting the relevant dropdown boxes, there is already an onChange command assigned that looks like

onchange="DP_jQuery_1353406309923.datepicker._selectMonthYear('#datepicker', this, 'M');"

I don't want to overwrite this.

Thanks in advance


回答1:


Use the onChangeMonthYear option:

onChangeMonthYear

Called when the datepicker moves to a new month and/or year. The function receives the selected year, month (1-12), and the datepicker instance as parameters. this refers to the associated input field.

$(function() {
    $( "#datepicker1" ).datepicker({
      changeMonth: true,
      changeYear: true,
      dateFormat: 'MM yy',
      altField: "#id",
      altFormat: "mm/yy",
      onChangeMonthYear: function(year, month, oDatepicker) {
        alert('Year: ' + year + ', Month: ' + month);
      }
    });
});​

Your fiddle, updated: http://jsfiddle.net/ff6Ex/1/



来源:https://stackoverflow.com/questions/13471386/how-to-add-onchange-event-to-dropdown-boxes-of-jquery-datepicker

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