JavaScript 中的事件绑定具有可互换的接口
我有一个应用程序,它有两个可互换的部分,需要不同的标记和不同的代码。我所说的可互换是指用户可以在两个界面之间即时切换。目前我的方法是,当用户第一次加载页面时,仅加载所需的标记和代码。当事件表明接口需要切换时,我通过 AJAX 加载新的标记。
我的问题涉及事件的绑定。目前,我的所有事件都被委托并附加到 DOM 中上游的元素,我知道这些元素将永远存在。
这种事件绑定有什么后果吗?动态绑定/重新绑定事件会更好吗?
I've got an application which has two interchangeable parts which require different markup and different code. By interchangeable, I mean the user can switch between the two interfaces on the fly. Currently my approach is such that when the user first loads the page, only the required markup and code is loaded. When an event signals that the interfaces need to be switched, I load the new markup via AJAX.
My question relates to the binding of events. Currently, all my events are delegated and attached to elements upstream in the DOM which I know will always be there.
Are there any consequences to this kind of event binding? Would I be better off binding/rebinding events on the fly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论