我是JavaScript新手,只想將我的JavaScript代碼放入另一個文件中。無法從我的HTML頁面調用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")
}
我假設,我只是做一個初學者的錯誤,因爲它似乎真的常見,但我無法弄清楚。
我認爲你只需要正確地格式化你的代碼。 'scr'? 'type =「button」,'<=逗號?.等...... – elclanrs