我可以将 onSelect jQuery UI DatePicker 事件与内联日期选择器一起使用吗?

发布于 2024-10-29 22:53:54 字数 536 浏览 4 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜无邪 2024-11-05 22:53:55

尝试一下 EmCo 在他的评论中建议的内容。如果它不起作用,您还可以通过编写自己的事件处理程序来“破解”它。您必须找到匹配的选择器来选择日历中的日期,然后将您的活动附加到它们。

$(Matching_day_selector).live('click', function(){
  // do what you need
});

编辑:使用 live() 可能是必要的;根据此演示的匹配选择器应该是:

$('.ui-state-default')

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')
遇见了你 2024-11-05 22:53:55

为了清楚起见,我最终得到的工作代码如下。

$("div.datepicker").datepicker({
    firstDay: 1,
    beforeShowDay: $.datepicker.noWeekends,
    altField: 'input#datepicker_val',
    onSelect: function(){
         updateTable("datepicker")
    }
});

非常感谢 EmCo 提供的解决方案,并感谢 Dampe 的投入。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文