JavaScript 中的事件绑定具有可互换的接口

发布于 2025-01-05 04:15:04 字数 228 浏览 1 评论 0原文

我有一个应用程序,它有两个可互换的部分,需要不同的标记和不同的代码。我所说的可互换是指用户可以在两个界面之间即时切换。目前我的方法是,当用户第一次加载页面时,仅加载所需的标记和代码。当事件表明接口需要切换时,我通过 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 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文