【发布时间】:2016-05-05 01:14:51
【问题描述】:
我在一个有角度的单页应用程序中使用 smarty street jquery.liveaddress 插件。当我转换到下一页时,我需要从 liveaddress 实例中解除所有事件侦听器的绑定。现在,如果我回到页面,所有事件都会触发两次,然后在下一次在页面上触发 3 次。
我已经尝试了我能想到的一切。我的最后一个解决方案是从 $(document) 中取消绑定所有事件名称,因为它看起来像是插件将所有事件附加到的位置。但即使这样也没有用。
jQuery(document).unbind("AddressChanged");
jQuery(document).unbind("AutocompleteUsed");
jQuery(document).unbind("VerificationInvoked");
jQuery(document).unbind("RequestSubmitted");
jQuery(document).unbind("ResponseReceived");
jQuery(document).unbind("RequestTimedOut");
jQuery(document).unbind("AddressWasValid");
jQuery(document).unbind("AddressWasAmbiguous");
jQuery(document).unbind("AddressWasInvalid");
jQuery(document).unbind("AddressWasMissingSecondary");
jQuery(document).unbind("OriginalInputSelected");
jQuery(document).unbind("UsedSuggestedAddress");
jQuery(document).unbind("InvalidAddressRejected");
jQuery(document).unbind("AddressAccepted");
jQuery(document).unbind("Completed");
【问题讨论】:
-
我注意到在这个取消绑定调用列表中,您错过了“AutocompleteInvoked”和“AutocompleteReceived”。调用 unbind 确实会分离事件。
标签: javascript jquery jquery-plugins smartystreets