我有一个 html 文件:index.html,其中包含一些基本的 js 库。 我还有一些模块:
a.html:
<div id='a'>
<script src="a1.js"></script>
<script src="a2.js"></script>
</div>
a1.js:
console.log('a1')
a2.js:
console.log('a2')
如何动态加载a.html到index.html中并获取a1.js和a2.js执行完成的事件?
最佳答案
使用 w3data.js
来执行此操作 ( w3data.js )
示例:在index.html
<html>
<script src="http://www.w3schools.com/lib/w3data.js"></script>
<body>
<div w3-include-html="a.html"></div>
<script>
w3IncludeHTML();
</script>
</body>
</html>
关于javascript - 如何动态加载html文件并执行其中的外部js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41085309/