我试图从其他地方获取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 page:
alert("work?");
答案 0 :(得分:0)
你创建了http服务器,哪个监听80端口? localhost使用if本地服务器,如果要加载本地文件 - 使用文件路径(不是服务器localhost)。