0
0

JavascriptをHTMLで使う

Last updated at Posted at 2024-08-08

JavascriptをHTMLで使う方法

外部のJavascriptファイルをindex.htmlで読み込み動作させる。

  • フォルダ構成
.
├─js
| └─sample.js
└─index.html
  • 実装
index.html
<!DOCTYPE html>
<html lang="ja">
 <head>
    <meta charset="uft-8">
    <script src="js/sample.js" async></script>
    <title>HTML入門-JavaScriptの基本</title>
 </head>
 <body>
    <h1>文書の主見出し</h1>
    <button type="button" onclick="ShowAlert()">ここをクリック</button>
 </body>
</html>
sample.js
function ShowAlert() {
    alert("Hello world!!");
}
  • 結果
    image.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