jQuery UI 事件功能扩展

发布于 2024-12-24 17:29:15 字数 336 浏览 3 评论 0原文

我想在关闭时添加自动销毁对话框的功能,而不向当前项目中的每个对话框调用添加任何特殊代码。所以我认为它需要重写默认的对话框 close 事件。

我找到了一种方法来做到这一点(例如:如何扩展 jquery ui 小部件?(1.7)),但我不想只覆盖该事件:我还需要保存该事件的先前行为并添加$(this).dialog("destroy") 在其之后调用。

有什么建议吗?

I want to add functionality of auto-destroying dialog on close without adding any special code to every dialog call in the current project. So I think it needs to override the default dialog close event.

I found a way to do this (for example: How to extend a jquery ui widget ? (1.7)), but I don't want just override the event: I also need to save the previous behavior of the event and add $(this).dialog("destroy") call after it.

Any suggestions?

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

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

发布评论

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

评论(2

冷月断魂刀 2024-12-31 17:29:15

我不是 100% 确定其正确性,但我认为您可以安全地重写 close 方法,如下所示:

$.ui.dialog.prototype._originalClose = $.ui.dialog.prototype.close;
$.ui.dialog.prototype.close = function() {
        alert ('My stuff');
        $.ui.dialog.prototype._originalClose.apply(this, arguments);
};

您可以在以下位置看到此方法: http://jsfiddle.net/8KKMm/

但是,避免覆盖外部库通常是一个好主意。可能有更好的方法来实现您的目标,而无需使用 jQuery UI 库。请查看对话框组件的可用事件: http://jqueryui.com/demos/dialog/

I'm not 100% sure about the correctness of this, but I think you can safely override the close method like this:

$.ui.dialog.prototype._originalClose = $.ui.dialog.prototype.close;
$.ui.dialog.prototype.close = function() {
        alert ('My stuff');
        $.ui.dialog.prototype._originalClose.apply(this, arguments);
};

You can see this working at: http://jsfiddle.net/8KKMm/

However, it's normally a good idea to avoid overriding external libraries. There might be better ways to achieve your target without mangling with jQuery UI library. Please do have a look at the available events of the Dialog component: http://jqueryui.com/demos/dialog/.

帅冕 2024-12-31 17:29:15

您可以将 dialogclose 处理程序添加到页面的 body 元素。

您可以在此处找到示例。

无需重写对话框类的close函数,只需使用对话框类提供的事件即可。

前任:

$("body").on("dialogclose", function(){
    alert("closed");
});

You can add a dialogclose handler to the body element of the page.

You can find a sample here.

There is no need to override the close function of the dialog class, you can simply use the events provided by the dialog class.

Ex:

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