我可以将 onSelect jQuery UI DatePicker 事件与内联日期选择器一起使用吗?
我正在尝试使用 jQuery UI 日期选择器作为内联日历。用户单击日历上的日期,它会运行 AJAX 请求以仅返回所选日期的数据。
例如,我编写的 AJAX 函数在从按钮调用时工作正常,但我无法让日期选择器调用它。这个想法是用户单击一个日期,然后调用该函数。我认为这就是 onSelect 事件的用途,但它似乎不起作用。
这是我在日期选择器上使用的代码。
$("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
});
日期选择器初始化良好。它显示并按预期运行,但无论我尝试什么(并且我花了几个小时寻找可能的解决方案),我都无法显示该警报。我错过了什么吗?
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 missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下 EmCo 在他的评论中建议的内容。如果它不起作用,您还可以通过编写自己的事件处理程序来“破解”它。您必须找到匹配的选择器来选择日历中的日期,然后将您的活动附加到它们。
编辑:使用 live() 可能是必要的;根据此演示的匹配选择器应该是:
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.
edit: using live() might be necessary; Matching selector according to this demo should be:
为了清楚起见,我最终得到的工作代码如下。
非常感谢 EmCo 提供的解决方案,并感谢 Dampe 的投入。
To make it clear, the working code I ended up with is below.
Thanks a lot to EmCo for his solution, and dampe for his input.