解除绑定 - 删除 - 杀死一个 jQuery 插件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3502468/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unbind - Remove - Kill a jQuery plugin
提问by tsiokos
Is there a way to "unbind" a jQuery plugin from a jquery selector?
有没有办法从 jquery 选择器中“解除绑定”一个 jQuery 插件?
采纳答案by reko_t
You can unbind the plugin name from the jQuery prototype object with delete:
您可以使用 delete 从 jQuery 原型对象解除插件名称的绑定:
delete $.fn.pluginName;
This doesn't affect already initialized plugin instances though.
但这不会影响已经初始化的插件实例。
回答by Guffa
Generally no.
一般没有。
The plugin typically makes changes to the elements that you apply it to. Sometimes those can simply be undone by removing the attributes or unbinding the events that the plugin added, but the plugin would need to provide this functionality, or you would have to know exactly what to remove.
该插件通常会对您应用它的元素进行更改。有时,可以通过删除插件添加的属性或解除绑定事件来简单地撤消这些操作,但是插件需要提供此功能,或者您必须确切知道要删除的内容。
Sometimes plugins overwrite information so that you can't undo it without knowing what the information was before the plugin was applied.
有时插件会覆盖信息,因此您无法在不知道应用插件之前的信息的情况下撤消它。
回答by anguswild
$("#selector").unbind().removeData();