通过 DOM 操作从 iFrame 移动内容后,如何确保 AJAX 仍然有效

发布于 2024-09-02 06:50:25 字数 171 浏览 3 评论 0原文

提交 iFrame 后,将返回启用 AJAX 功能的内容,一切正常。

一旦我通过 DOM 操作将内容从 iFrame 移至主页并删除 iFrame,AJAX 就会停止工作。

我怎样才能让它发挥作用?

我抓取 iFrame 的正文内容并通过 .innerHTML 将其移动到外部元素

After submitting an iFrame, content with AJAX enabled functions is returned and everything works.

Once I move the content out from the iFrame to the main page through DOM manipulation and remove the iFrame, AJAX stops working.

How can I make it work?

I grab the body content of the iFrame and move it to an outside element through .innerHTML

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦初启 2024-09-09 06:50:25

它实际上取决于 AJAX 实现...

一旦您从 iFrame 中获取 DOM 节点并将它们放入您的 << body >,它们本质上是新的 DOM 节点。附加到它们的任何事件都需要重新执行,并且与它们交互的任何代码都需要重新执行。

为什么不简单地将 iFrame 加载到主页的 DOM 中并在那里执行 AJAX 代码呢?

It really depends on the AJAX implementation...

Once you've grabbed the DOM nodes from the iFrame and placed them in your < body >, they are essentially new DOM nodes. Any events attached to them would need to be rebound and any code interacting with them would need to be re-executed.

Why not simply load the iFrame into the main page's DOM to begin with and execute the AJAX code there?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文