javascript - html 是,但在 onclick 函数之后 JavaScript 没有在 div 中呈现

标签 javascript php html rendering

我正在使用按钮 onclick 函数将内容加载到索引页上名为 #content 的 div 中。 以下是单击 JavaScript 函数。

function myFunction() {

   $('#content').load("content/page1.php");

};

它工作正常,但是当它获取加载的 php 文件时,专门针对该 page1.php 的所有 javascript 都不会在 #content div 中呈现。 html 渲染得很好。如果您在浏览器地址栏中输入 page1.php 的绝对路径,则 page1.php javascript 也可以正常呈现。

关于如何在 #content div 中渲染 javascript 有什么想法吗? 我正在使用较新版本的 chrome。

最佳答案

根据 load 的文档,

When calling .load() using a URL without a suffixed selector expression, the content is passed to .html() prior to scripts being removed. This executes the script blocks before they are discarded.

我建议您考虑重构您的 JavaScript,以便在有意义的情况下将其加载到父页面内的模块中,因为它使事情更容易调试。如果这不是一个选项,脚本 block 仍会执行...

关于javascript - html 是,但在 onclick 函数之后 JavaScript 没有在 div 中呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32345456/

相关文章:

javascript - 如何在同构 react 应用程序中调用窗口函数?

javascript - data studio,数据变化时如何移除 Canvas ?

具有 100% 溢出滚动的 HTML 表格,仅适用于表格

php - 从 Python 发送 HTTP POST 请求(尝试从 PHP 转换)

php - 是否可以从 Mysql 行数据中制作元描述和关键字

html - 我想让文本稍微居中,但它跳到一个新行

javascript - 从 HTML/CSS/JS 应用程序发送电子邮件

javascript - Gulp 退出太早

javascript - 使用浏览器扩展程序将显示 "Hello World"的小部件添加到已定义的网页

javascript - 如何从索引1开始每个函数以在html中的不同div中发布json对象