jQuery UI 事件功能扩展
我想在关闭时添加自动销毁对话框的功能,而不向当前项目中的每个对话框调用添加任何特殊代码。所以我认为它需要重写默认的对话框 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不是 100% 确定其正确性,但我认为您可以安全地重写 close 方法,如下所示:
您可以在以下位置看到此方法: 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:
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/.
您可以将
dialogclose
处理程序添加到页面的body
元素。您可以在此处找到示例。
无需重写对话框类的close函数,只需使用对话框类提供的事件即可。
前任:
You can add a
dialogclose
handler to thebody
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: