我试图简单地调用一个在外部文件中找到的 JavaScript 函数。我的文件夹结构是:
C:\xampp\htdocs\test\index.php
C:\xampp\htdocs\test\js\functions.js
索引.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="css/stylesheet.css"/>
<title>Home</title>
</head>
<body>
<?php include("header.php"); ?>
<?php include("content.php"); ?>
<script src="https://kit.fontawesome.com/f0aaae8537.js"></script>
<script src="/js/functions.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
<script>
test();
</script>
</html>
函数.js
function test(){
alert("where am i");
}
我正在使用 VS Code 和 XAMPP。未调用功能测试。当我在 index.php 中定义函数但不在外部文件中时,它起作用。我试过包括属性 type="text/javascript" 并将functions.js 文件移动到根文件夹“test”,但仍然没有。
汪汪一只猫
倚天杖
料青山看我应如是