以下方法可以动态加载js文件: <html> <head> <script> function a(){ var s=document.createElement("script") s.src="test.js" document.body.insertAdjacentElement("beforeBegin",s) //test() is a function of test.js test() } </script> </head> <body onload="a()"> </body> </html>
<html>
<head>
<script>
function a(){
var s=document.createElement("script")
s.src="test.js"
document.body.insertAdjacentElement("beforeBegin",s)
//test() is a function of test.js
test()
}
</script>
</head>
<body onload="a()">
</body>
</html>