如何取消手风琴控件的更改事件

发布于 2024-10-05 00:32:25 字数 227 浏览 2 评论 0原文

$("#accordion").accordion({
    change: function (event, ui) {
        alert('event have to be changed')
    },
    changestart: function (event, ui) {
       return false;
    }
});

是否可以取消更改事件?

$("#accordion").accordion({
    change: function (event, ui) {
        alert('event have to be changed')
    },
    changestart: function (event, ui) {
       return false;
    }
});

Is it possible to cancel the change event?

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

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

发布评论

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

评论(6

锦爱 2024-10-12 00:32:25

我不确定更改,但对于 jqueryui 中的其他事件返回 false 会取消该事件。

I am not sure about change but for other events in jqueryui returning false cancels the event.

给妤﹃绝世温柔 2024-10-12 00:32:25

stopPropagation() 是停止处理 jQueryUI 操作的关键,但它必须在changestart 事件之前中断。例如,当实际单击标题项时。

如果这是手风琴中的标题/内容对:

<h3 class='noexpand'>This is a dummy header</h3>
<div>This is dummy content</div>

那么这将阻止手风琴在单击标题时展开 div:

$("h3.noexpand").click(function(e) {
    e.stopPropagation();
});

请参阅 jquery Accordion 防止冒泡/允许默认链接操作

stopPropagation() is the key to stopping a jQueryUI action from processing, but it must be interrupted BEFORE the changestart event. For example, when the header item is actually clicked.

If this is a header/content pair in your accordion:

<h3 class='noexpand'>This is a dummy header</h3>
<div>This is dummy content</div>

Then this will prevent the accordion from expanding the div when the header is clicked:

$("h3.noexpand").click(function(e) {
    e.stopPropagation();
});

See jquery accordion prevent bubbling / allow default link action.

最偏执的依靠 2024-10-12 00:32:25

正如马丁所说,你可以返回 false。请参阅下面的代码示例。

...
eventname: function( event, ui ) {
    // Add your code here
    ...

    return false;
}

As Martin said you can return false. See a code sample below.

...
eventname: function( event, ui ) {
    // Add your code here
    ...

    return false;
}
忱杏 2024-10-12 00:32:25
event.preventDefault();
event.stopPropagate();
event.preventDefault();
event.stopPropagate();
小镇女孩 2024-10-12 00:32:25

返回 false 不会执行任何操作,要取消 jQueryUI 中的事件,您需要对该事件调用 PreventDefault()。

$("#accordion").accordion({
    changestart: function (event, ui) {
       event.preventDefault();
    }
});

这应该适用于所有事件方法,包括自动完成。如果您希望在自动完成菜单中包含一些自定义选项,您希望有人选择这些选项,但实际上不想添加到与其关联的输入中,那么这会很方便。 :)

Returning false does nothing, to cancel an event in jQueryUI you need to call preventDefault() on the event.

$("#accordion").accordion({
    changestart: function (event, ui) {
       event.preventDefault();
    }
});

This should work with all event methods, including autocomplete. Handy if you wish to include a few custom options in your autocomplete menu that you want someone to select but don't actually want to add to the input it is tied to. :)

可是我不能没有你 2024-10-12 00:32:25

对我有用的是调用:

function onChange(e, ui) {
    e.preventDefault();
    e.stopPropagation();
}

在函数末尾返回 false 具有相同的效果,因为它相当于进行这两个函数调用。

What worked for me is calling:

function onChange(e, ui) {
    e.preventDefault();
    e.stopPropagation();
}

Returning false at the end of the function has the same affect because it's the equivalent of making those two function calls.

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