//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!
所以最近我尝试在网页上实现一些javascript
库。但是html
不会从其他js文件中调用任何内容。我尝试了很多东西,从js文件中调用简单的函数,有时它可以工作,但是当我删除测试时,函数页面将显示与函数仍然存在相同的结果。它需要很长时间才能响应 js 的变化。 我什至尝试过不同的设备。
任何事情将不胜感激!
编辑:当我发布这个时,我将功能从"Allertt"修改为"Hello! 现在,我在 5 小时后检查了脚本已更新。另外,是的,这是在服务器上在线运行的。
我为您准备了一个示例,效果很好:
网页文件
<!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,就像它应该的那样。