我正在使用按钮 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/