jQuery UI 切换按钮事件

发布于 2024-09-25 19:41:06 字数 454 浏览 0 评论 0原文

如何将事件绑定到 jQuery UI 切换按钮?更具体地说,如何绑定将要触发的事件?

复选框正在渲染以正确切换按钮,但当按钮状态更改时,不会触发附加到它们的任何事件处理程序。我有什么遗漏的吗?

CSS:

<input type='checkbox' id='recording'/> <label for='recording'> Recording </label>

JavaScript:

$('#recording').button() // works
    .click(fn)           // doesnt work
    .changed(fn)         // doesnt work
    .toggle(fn, fn2)     // doesn't work

How do I bind events to a jQuery UI Toggle button? More specifically, how can I bind events that are going to fire?

The checkboxes are rendering to toggle buttons correctly, but any event handlers attached to them are not triggered when the state of the button changes. Is there something I'm missing?

CSS:

<input type='checkbox' id='recording'/> <label for='recording'> Recording </label>

JavaScript:

$('#recording').button() // works
    .click(fn)           // doesnt work
    .changed(fn)         // doesnt work
    .toggle(fn, fn2)     // doesn't work

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

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

发布评论

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

评论(1

亣腦蒛氧 2024-10-02 19:41:06

假设 jQuery-UI 切换按钮没有什么特别奇怪的:

$('#recording').live('click',
function() {
// the stuff you want to do when the future-created buttons are clicked
});

文档,来自 http://api.jquery.com/< /a>,在 live 事件处理程序上。

代替'click

  • 您还可以使用: (jQuery 1.3.x)'dblclick'、'keydown'、'keypress'、'keyup'、'mousedown'、'mousemove'、'mouseout'、'mouseover' 和 ' '。 mouseup'
  • (jQuery 1.4.1) 以上所有内容,加上:'焦点'、'模糊'和'悬停'。

有关完整详细信息,请参阅 http://api.jquery.com/live/ 参考。

正如@Peter Ajtai 指出的(在评论中):

如果列出了可以绑定的所有事件,则还应该列出自定义事件,并且可以通过在每对事件之间留一个空格来包含多个事件

强调我的)

Assuming that there's nothing particularly odd about the jQuery-UI toggle buttons:

$('#recording').live('click',
function() {
// the stuff you want to do when the future-created buttons are clicked
});

Documentation, from http://api.jquery.com/, on the live event-handler.

In place of 'click' you can also use:

  • (jQuery 1.3.x) 'dblclick', 'keydown', 'keypress', 'keyup', 'mousedown', 'mousemove', 'mouseout', 'mouseover' and 'mouseup'
  • (jQuery 1.4.1) all the above, plus: 'focus', 'blur' and 'hover'.

See the http://api.jquery.com/live/ reference for full details.

As @Peter Ajtai noted (in comments):

If you list all the events you can bind, you should also list custom events and that you can include multiple events by leaving a space between each pair of events.

(Emphasis mine)

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