[英]Get js (node.js) code from html page and run it after load
我正在嘗試從其他地方獲取js代碼並運行它,但加載后未運行
有人知道如何跑步嗎? (代碼在這里)
謝謝
<html>
<head>
</head>
<body>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.src = 'http://localhost/check.js';
document.getElementsByTagName('head')[0].appendChild(script);
}
</script>
</body>
</html>
js頁面:
alert("work?");
您創建了http服務器,哪個監聽80端口? 本地主機使用if本地服務器,如果要加載本地文件-使用文件路徑(而不是服務器本地主機)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.