File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
docs/1-trial-session/14-events Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -3,8 +3,12 @@ title: イベント
33---
44
55import Term from "@site/src /components/Term";
6+ import Details from "@theme/Details ";
7+ import CodeBlock from '@theme/CodeBlock ';
8+ import ViewSource from "@site/src /components/ViewSource";
69
710import handleClickVideo from "./handle-click.mp4";
11+ import projectMovieForDom from "./project-movie-for-dom.mp4";
812
913## <Term type =" javascriptValue " >値</Term >としての<Term type =" javascriptFunction " >関数</Term >
1014
@@ -71,3 +75,34 @@ greetButton.onclick = clicked();
7175上の例では、画面上にはじめから表示されていたボタンが、ボタンをクリックしたときに削除されています。これは、 ` document.write ` をすべての<Term type =" element " >要素</Term >の表示が終わった後に実行すると、画面上のすべての<Term type =" element " >要素</Term >を一度削除するという挙動をとるためです。このため、現代の <Term type =" javascript " >JavaScript</Term > において、 ` document.write ` <Term type =" javascriptFunction " >関数</Term >が使用されることはほとんどありません。
7276
7377:::
78+
79+ ## 課題
80+
81+ 押すと大きく赤文字が表示される「びっくり箱」のようなボタンを作ってみましょう。
82+
83+ <video src ={projectMovieForDom} autoPlay muted loop controls />
84+
85+ <Details summary ={<summary >ヒント1:文字列の表示</summary >}>
86+
87+ さっきは文字列の表示に` document.write(); ` を使いましたが、これでは文字色やサイズが変えられません。
88+ こんな書き方ならそれもできますが、あまりに乱暴ですよ。
89+
90+ ``` javascript
91+ document .write (" <div style='color:red; font-size:40px'>Hello world!</div>" );
92+ ```
93+
94+ 文字列をJavaScriptで操作する方法は前回の「DOM」の章で扱っています。
95+
96+ </Details >
97+
98+ <Details summary ={<summary >ヒント2:HTMLファイルに…</summary >}>
99+
100+ ` <button> ` タグのHTML属性を書き換えるとボタンの中に` Hello world! ` を表示してしまいます。
101+
102+ HTMLファイルに一工夫が必要です。見えない` <div> ` タグを用意してあげましょう。
103+
104+ ``` html
105+ <div id =" greeting" ></div >
106+ ```
107+
108+ </Details >
You can’t perform that action at this time.
0 commit comments