teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

書き方の追記

2019/12/04 14:41

投稿

thyda.eiqau
thyda.eiqau

スコア2982

answer CHANGED
@@ -1,3 +1,27 @@
1
1
  > となるようにプログラムを書くことはできますでしょうか。
2
2
 
3
- はい、できます。
3
+ はい、できます。
4
+
5
+ ----
6
+ Dec 4, 2019 11:40pm 追記
7
+ > 可能であればその書き方を教えて頂けると幸いでございます。
8
+
9
+ とのことですので、追記します。
10
+
11
+ ちなみに、id属性にスペースを含めてはいけません ([MDM](https://developer.mozilla.org/ja/docs/Web/HTML/Global_attributes/id))
12
+ ```html
13
+ <script>
14
+ var fruits = ["りんご", "ばなな", "ぶどう"];
15
+
16
+ function arrayFunction() {
17
+ const elm = document.getElementById('text_id');
18
+ fruits.push(elm.value);
19
+
20
+ document.getElementById('array011').innerHTML = elm.value;
21
+ }
22
+ </script>
23
+
24
+ <input type="text" id="text_id" name="fruit">
25
+ <button onclick="arrayFunction()">クリック</button>
26
+ <p id="array011"></p>
27
+ ```