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

回答編集履歴

5

追記の追記

2016/12/06 07:39

投稿

退会済みユーザー
answer CHANGED
@@ -102,4 +102,47 @@
102
102
  </body>
103
103
  </html>
104
104
  ```
105
-
105
+ 補足の補足
106
+ ---
107
+ 直近で打ち込まれた文字を認識するには[lastIndexOfメソッド](http://www.ajaxtower.jp/js/string_class/index15.html)を使用すると実現できます。
108
+ ```HTML
109
+ <!DOCTYPE html>
110
+ <html lang="ja">
111
+ <head>
112
+ <meta charset="utf-8">
113
+ <title>タイトル</title>
114
+ </head>
115
+ <body>
116
+ <div id="textarea1">
117
+ <textarea></textarea>
118
+ </div>
119
+ <div id="textarea2">
120
+ <p><span id="text">./a.out</span>と入力しましょう。</p>
121
+ <span id="intro"></span>
122
+ </div>
123
+ <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
124
+ <script>
125
+ var i = 0, commands = [
126
+ 'text',
127
+ 'text1',
128
+ 'text2',
129
+ 'text3'
130
+ ];
131
+ var intro = [
132
+ "textの説明",
133
+ "text1の説明",
134
+ "text2の説明",
135
+ "text3の説明"
136
+ ];
137
+ $("#textarea1 textarea").keypress(function () {
138
+ var lastLine = (this.value).substr((this.value).lastIndexOf("\n") + 1);
139
+ if (lastLine == $("#text").text()) {
140
+ $("#textarea2 p").html('次は、<span id="text">' + commands[i] + '</span>と入力しましょう<br>');
141
+ $("#intro").html(commands[i] + 'の説明: ' + intro[i]);
142
+ i++;
143
+ }
144
+ }).change();
145
+ </script>
146
+ </body>
147
+ </html>
148
+ ```

4

修正、追加

2016/12/06 07:39

投稿

退会済みユーザー
answer CHANGED
@@ -57,4 +57,49 @@
57
57
  </body>
58
58
  </html>
59
59
  ```
60
- わからないところとかあったらコメントとかでおしえてください。
60
+ わからないところとかあったらコメントとかでおしえてください。
61
+ 補足
62
+ ---
63
+ 説明を入れたいときも、上でやっていることを参考にすると簡単に実現できます。
64
+ 今回はtextarea2に新しくspan.introを追加してそこに説明を表示させています。
65
+ ```HTML
66
+ <!DOCTYPE html>
67
+ <html lang="ja">
68
+ <head>
69
+ <meta charset="utf-8">
70
+ <title>タイトル</title>
71
+ </head>
72
+ <body>
73
+ <div id="textarea1">
74
+ <textarea></textarea>
75
+ </div>
76
+ <div id="textarea2">
77
+ <p><span id="text">./a.out</span>と入力しましょう。</p>
78
+ <span id="intro"></span>
79
+ </div>
80
+ <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
81
+ <script>
82
+ var i = 0, commands = [
83
+ 'text',
84
+ 'text1',
85
+ 'text2',
86
+ 'text3'
87
+ ];
88
+ var intro = [
89
+ "textの説明",
90
+ "text1の説明",
91
+ "text2の説明",
92
+ "text3の説明"
93
+ ];
94
+ $("#textarea1 textarea").change(function () {
95
+ if ($(this).val() == $("#text").text()) {
96
+ $("#textarea2 p").html('次は、<span id="text">' + commands[i] + '</span>と入力しましょう<br>');
97
+ $("#intro").html(commands[i] + 'の説明: ' + intro[i]);
98
+ i++;
99
+ }
100
+ }).change();
101
+ </script>
102
+ </body>
103
+ </html>
104
+ ```
105
+

3

修正

2016/12/05 11:36

投稿

退会済みユーザー
answer CHANGED
@@ -49,7 +49,7 @@
49
49
  ];
50
50
  $("#textarea1 textarea").change(function () {
51
51
  if ($(this).val() == $("#text").text()) {
52
- $("#textarea2 p").html('次は、<span id="text">' + commands[i] + 't</span>と入力しましょう');
52
+ $("#textarea2 p").html('次は、<span id="text">' + commands[i] + '</span>と入力しましょう');
53
53
  i++;
54
54
  }
55
55
  }).change();

2

修正

2016/12/03 06:18

投稿

退会済みユーザー
answer CHANGED
@@ -23,4 +23,38 @@
23
23
  </script>
24
24
  </body>
25
25
  </html>
26
- ```
26
+ ```
27
+ 決められたコマンドというのが2つ以上あるならこんな感じにすればいいんじゃないでしょうか。
28
+ ```HTML
29
+ <!DOCTYPE html>
30
+ <html lang="ja">
31
+ <head>
32
+ <meta charset="utf-8">
33
+ <title>タイトル</title>
34
+ </head>
35
+ <body>
36
+ <div id="textarea1">
37
+ <textarea></textarea>
38
+ </div>
39
+ <div id="textarea2">
40
+ <p><span id="text">./a.out</span>と入力しましょう。</p>
41
+ </div>
42
+ <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
43
+ <script>
44
+ var i = 0, commands = [
45
+ 'text',
46
+ 'text1',
47
+ 'text2',
48
+ 'text3'
49
+ ];
50
+ $("#textarea1 textarea").change(function () {
51
+ if ($(this).val() == $("#text").text()) {
52
+ $("#textarea2 p").html('次は、<span id="text">' + commands[i] + 't</span>と入力しましょう');
53
+ i++;
54
+ }
55
+ }).change();
56
+ </script>
57
+ </body>
58
+ </html>
59
+ ```
60
+ わからないところとかあったらコメントとかでおしえてください。

1

修正

2016/12/03 00:04

投稿

退会済みユーザー
answer CHANGED
@@ -9,7 +9,6 @@
9
9
  <body>
10
10
  <div id="textarea1">
11
11
  <textarea></textarea>
12
- <p id="output"></p>
13
12
  </div>
14
13
  <div id="textarea2">
15
14
  <p><span id="text">./a.out</span>と入力しましょう。</p>