Javascript Prompt() 只能内联工作,不能在外部文件中工作

Javascript Prompt() only working inline and not in external file

我有一个 prompt() 变量,它仅在 html 文件中的 <script> 标记内有效,但由于某些限制条件我无法做到。相反,我将它放在 .js 文件中,但是当我刷新页面时它不会提示我。文件已加载,但没有任何反应。知道为什么会这样吗?

更新代码

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();

<!DOCTYPE html>
<html lang="en">
<head>
    <title></title>

    <link rel="stylesheet" type="text/css" href="index.css">

    <script type="text/javascript" href="index.js"></script>
</head>
<body>
    <div class="display">

    </div>
</body>
</html>
<script type="text/javascript" href="index.js"></script>

您要查找的属性是 src 而不是 href

使用a validator.