html没有响应外部js文件更改

时间:2017-07-30 09:10:56

标签: javascript html html5



//index.php
<head>
    
<script src="/js/test.js"></script>

<style></style>
</head>

<body>
<script>
callalert();
</script>

</body>





//test.js
function callalert() {
alert('Allertt');
}

eg: i change the fn completely to: callalert(msg) {
var msg;
alert(msg);
}

//and html to:

callalert('Hello!');

//and it wont change, it still says "Allertt"

Anything would be appreciated!
&#13;
&#13;
&#13;

所以最近我试图在网页上实现一些javascript库。但html不会从其他js文件中调用任何内容。我尝试了很多东西,从js文件调用简单的函数,并且它有效但是当我删除测试时,函数页面将显示相同的结果,因为函数仍然存在。它需要很长时间才能响应js的变化。 我甚至试过不同的设备。

任何事情都会受到赞赏!

编辑:当我发布这个时,我修改了&#39; Allertt&#39;到你好!&#39;。 现在,我在5小时后检查脚本是否已更新。此外,是的,这是在服务器上在线运行。

1 个答案:

答案 0 :(得分:-1)

我为你准备了一个完美的例子:

HTML文件

<!DOCTYPE html>
<html>
<head>
    <title>test</title>
    <script type="text/javascript" src="test.js"></script>
</head>
<body>


<script>
    myFun();
</script>
</body>
</html>

外部JS

function myFun(){
    alert('test');
}

这会在每次刷新时从外部文件调用myFun,就像它应该的那样。