概要
JavaScriptで「JavaScriptのコードを別のファイルに記述する」の動作を確認してみました。
以下のページを参考にしました。
実装
以下のファイルを作成しました。
sample.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>JavaScript サンプル</title>
</head>
<body>
<p>
この下に JavaScript を使って文字列を出力します。
</p>
<script src="./sample.js">
</script>
</body>
</html>
sample.js
document.write("<p>JavaScriptファイルの読み込みテスト</p>");
実行結果は以下の通りでした。
まとめ
何かの役に立てばと。