无法根据按钮的类别选择按钮

发布于 2024-12-25 08:42:10 字数 730 浏览 6 评论 0原文

我希望我的 jQuery 日期选择器 (jQuery UI 1.8.13) 仅在单击“完成”按钮时生成报告。

在此处输入图像描述

onClose 事件不好,因为当我单击某处时也会触发该事件否则(不在日期选择器中),我只需要在按下“完成”按钮时生成报告。因此,我需要向“完成”按钮添加一个 onclick 回调。但是我找不到与“完成”按钮匹配的 jQuery 选择器。我已经尝试过 $('.ui-corner-all') 但这也会找到其他元素。 所以,我尝试了 $('.ui-priority-primary') (因为据我所知,这是唯一具有这种样式的元素),但它与按钮不匹配......

  1. 我需要一个仅匹配“完成”按钮的选择器。
  2. 为什么 $('.ui-priority-primary') 不起作用?

请在此处找到示例代码。

更新 我使用这个日期选择器作为月份选择器,所以我没有要点击的日期。因此,正如我上面所说,我需要将回调放在“完成”按钮上,这一点很重要。

I want my jQuery datepicker (jQuery UI 1.8.13) to generate a report only when I click the 'Done' button.

enter image description here

The onClose event is not good because that is triggered also when I click somewhere else (not in the datepicker) and I need to generate the report only when the 'Done' button is pressed. Therefore I need to add an onclick callback to the 'Done' button. However I can not find a jQuery selector that will match the 'Done' button. I have tried the $('.ui-corner-all') but that will also find other elements too.
So, I have tried $('.ui-priority-primary') (because AFAIK this is the only element that has this style), but it does not match the button ...

  1. I need a selector that will only match that 'Done' button.
  2. Why is $('.ui-priority-primary') not working?

Please find the sample code here.

UPDATE I use a this datepicker as a monthpicker, so I do not have dates to click on. Therefore it is important that I need to put the callback on the 'Done' button as I have stated above.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

命硬 2025-01-01 08:42:10

如何使用 onSelect 事件,该事件在选择日期:

$('.date').datepicker({
    onSelect: function(dateText, inst) { 
        ...
    }
});

How about using the onSelect event which is triggered when a date is selected:

$('.date').datepicker({
    onSelect: function(dateText, inst) { 
        ...
    }
});
涙—继续流 2025-01-01 08:42:10

就它不起作用而言,这是因为控件是在绑定发生后创建的。如果您使用委托,那么它将起作用。虽然我认为达林的答案可能是一个更好的解决方案,但我提供这个答案是因为它直接回答了你问题的“原因”。

http://jsfiddle.net/7ThB8/30/

$('body').delegate('.ui-priority-primary', 'click', function() {
    alert('done was clicked');
});

As far as it not working, this is because the control is created after your binding takes place. If you use delegate then it will work. Although I think Darin's answer is probably a better solution, I am providing this as it directly answers the 'why' of your question.

http://jsfiddle.net/7ThB8/30/

$('body').delegate('.ui-priority-primary', 'click', function() {
    alert('done was clicked');
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文