I'm trying to use the jQuery UI datepicker as an inline calendar. A user clicks a date on the calendar, and it runs an AJAX request to return data only from the chosen date.
The AJAX function I've written works fine when it's called from a button, for example, but I can't get the date picker to call it. The idea is that the user clicks a date and the function is then called. I thought that is what the onSelect event is for, but it doesn't seem to work.
Here is the code I'm using on the date picker.
$("div.datepicker").datepicker({
firstDay: 1,
beforeShowDay: $.datepicker.noWeekends,
altField: 'input#datepicker_val',
onSelect: alert("Select event worked.") // this will be replaced with the ajax function call
});
The datepicker is initialised fine. It shows up and behaves as expected, but no matter what I try (and I've spent hours looking up possible solutions), I can't get that alert to show up. Am I mi开发者_JAVA百科ssing something?
Try what EmCo suggested in his comment. If it won't work, you can also 'hack' it by writing your own event handler. You will have to find matching selector to select days in calendars, and then attach your event to them.
$(Matching_day_selector).live('click', function(){
// do what you need
});
edit: using live() might be necessary; Matching selector according to this demo should be:
$('.ui-state-default')
To make it clear, the working code I ended up with is below.
$("div.datepicker").datepicker({
firstDay: 1,
beforeShowDay: $.datepicker.noWeekends,
altField: 'input#datepicker_val',
onSelect: function(){
updateTable("datepicker")
}
});
Thanks a lot to EmCo for his solution, and dampe for his input.
精彩评论