gpt4 book ai didi

javascript - 无法从我的 html 页面调用 javascript 文件

转载 作者:行者123 更新时间:2023-11-28 11:37:15 25 4
gpt4 key购买 nike

我是 JavaScript 新手,只想将我的 JavaScript 代码放在另一个文件中。

这是我的 html 页面:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>my badass page</title>
<script type="text/javascript" scr = "testing.js"></script>//this contains the function I want to call
</head>
<body id="body">
<button type="button", onclick="showDate()">show the date</button>
</body>
</html>

这是testing.js 文件:

function showDate() {
alert ("this works")
}

我假设我只是犯了一个初学者错误,因为它看起来很常见,但我无法弄清楚。

最佳答案

您代码中的“src”属性拼写错误

你拼写了scr,它应该是src

这个:

<script type="text/javascript" scr = "testing.js"></script>

应该是这样的:

<script type="text/javascript" src = "testing.js"></script>

关于javascript - 无法从我的 html 页面调用 javascript 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16616777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com