0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【初歩】JavaScriptの読み込み console出力 HelloWorld!

Last updated at Posted at 2021-06-09

##①html内でjavascriptを読み込む

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <!-- htmlの中にjavascriptを読み込む場合 -->
  <script>
    console.log('Hello World!');
  </script>
  <!-- htmlの中にjavascriptを読み込む場合 -->
</body>
</html>

##②別のフォルダでscript.jsを読み込む場合

・jsフォルダの中にscript.jsを作ります。
スクリーンショット 2021-06-09 18.41.09.png

・script.jsに記述
クリーンショット 2021-06-09 19.16.28.png
src属性でscript.jsのフォルダを読み込みます。

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <!-- jsフォルダでjavascriptを読み込む場合 -->
  <script src="js/script"></script>
  <!-- jsフォルダでjavascriptを読み込む場合 -->
</body>
</html>

・index.htmlを読み込んで、検証(option + command + I)
consoleを選択してHelloWorld!と出てればOKです。
スクリーンショット 2021-06-09 19.28.37.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?