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

回答編集履歴

7

追記

2018/08/29 16:53

投稿

liveasnotes
liveasnotes

スコア1284

answer CHANGED
@@ -35,10 +35,12 @@
35
35
  liveweaveのリントがはくエラーを消そうとしてこう書きましたが,x_xさんのご指摘の通り,tr要素の直下にtr要素は書けないです.つまり,下のgifのようにやるのは間違いになります
36
36
  ![イメージ説明](5566c19d4efcae70aafa54dbf0128271.gif)
37
37
 
38
+ ---
39
+
40
+ #追記(20180830)
41
+
38
- 修正版
42
+ - 表組み修正版
39
43
  ```html
40
- <!--整えたバージョン-->
41
-
42
44
  <form class="form-control" action="./score" method="post">
43
45
  <table class="layout-set" border="0" cellspacing="0" cellpadding="0">
44
46
  <tr>
@@ -54,9 +56,9 @@
54
56
  </label>
55
57
  </td>
56
58
  </tr>
57
- <!-- 表示非表示切り替え -->
59
+ </table>
58
- <tr id="firstBox">
60
+ <table id="entry_as_user">
59
- <!--<tr> ←削除分-->
61
+ <tr>
60
62
  <th>ユーザー名:</th>
61
63
  <td><input type="text" class="form-control" placeholder="ユーザー名"/></td>
62
64
  </tr>
@@ -72,11 +74,13 @@
72
74
  <option value="5">E-team</option>
73
75
  </select>
74
76
  </td>
75
- <!-- <p>紹介された方のお名前を入力してください。</p></td> -->
76
77
  </tr>
78
+ <tr>
79
+ <td><button type="submit">SUBMIT_A</button></td>
80
+ </tr>
77
- <!-- 表示非表示切り替え -->
81
+ </table>
78
- <tr id="secondBox">
82
+ <table id="entry_as_team">
79
- <!--<tr> ←削除分-->
83
+ <tr>
80
84
  <th>チーム名:</th>
81
85
  <td><input type="text" class="form-control" placeholder="チーム名"/></td>
82
86
  </tr>
@@ -92,26 +96,30 @@
92
96
  <option value="5">User-E</option>
93
97
  </select>
94
98
  </td>
95
- <!-- <p>紹介された方のお名前を入力してください。</p></td> -->
96
99
  </tr>
97
-
100
+ <tr>
101
+ <td><button type="submit">SUBMIT_B</button></td>
102
+ </tr>
98
103
  </table>
99
104
  </form>
100
105
 
101
106
  <!--スクリプト-->
102
107
  <script type="text/javascript">
103
108
  function entryChange1(){
109
+ var eau = document.getElementById('entry_as_user');
110
+ var eat = document.getElementById('entry_as_team');
111
+
104
112
  radio = document.getElementsByName('entryPlan')
105
113
  if(radio[0].checked) {
106
114
  //フォーム
107
- document.getElementById('firstBox').style.display = "";
115
+ eau.style.display = "";
108
- document.getElementById('secondBox').style.display = "none";
116
+ eat.style.display = "none";
109
117
  //特典
110
118
  //document.getElementById('firstNotice').style.display = "";
111
119
  }else if(radio[1].checked) {
112
120
  //フォーム
113
- document.getElementById('firstBox').style.display = "none";
121
+ eau.style.display = "none";
114
- document.getElementById('secondBox').style.display = "";
122
+ eat.style.display = "";
115
123
  //特典
116
124
  //document.getElementById('firstNotice').style.display = "none";
117
125
  }
@@ -122,93 +130,68 @@
122
130
  </script>
123
131
  ```
124
132
 
125
- # 追記(20180829)
126
- これでどうでしょう.
133
+ - div版+css
127
- 単順に,いじりたい要素にidを振り分けて操作しているだけですが
128
- ![イメージ説明](4ff916dad21f42c3c85b149ead61b516.gif)
134
+ ![イメージ説明](be657f6dbd6f79c99c740d2429493d27.gif)
129
-
130
135
  ```html
131
136
  <form class="form-control" action="./score" method="post">
132
- <table class="layout-set" border="0" cellspacing="0" cellpadding="0">
133
- <tr>
137
+ <div>
134
- <th>登録種別</th>
138
+ <span>登録種別</span>
135
- <td>
136
- <label>
137
- <input type="radio" name="entryPlan" value="hoge1" onclick="entryChange1();" checked="checked" />
139
+ <label><input type="radio" name="entryPlan" value="hoge1" onclick="entryChange1();" checked="checked" />ユーザー</label>
140
+ <label><input type="radio" name="entryPlan" value="hoge2" onclick="entryChange1();" />チーム</label>
141
+ </div>
142
+
143
+ <div id="entry_as_user" class="form_contents">
138
- ユーザ
144
+ <label>ユーザ名:
145
+ <input type="text" class="form-control" placeholder="ユーザー名"/>
139
- </label>
146
+ </label>
140
- <label>
147
+ <label>チーム名:
148
+ <select class="custom-select">
149
+ <option selected>チーム選択</option>
150
+ <option value="1">A-team</option>
141
- <input type="radio" name="entryPlan" value="hoge2" onclick="entryChange1();" />
151
+ <option value="2">B-team</option>
152
+ <option value="3">C-team</option>
153
+ <option value="4">D-team</option>
154
+ <option value="5">E-team</option>
142
- チーム
155
+ </select>
143
- </label>
156
+ </label>
157
+ <button type="submit">SUBMIT_A</button>
144
- </td>
158
+ </div>
145
- </tr>
159
+
146
- <tr id="entry_input_user">
160
+ <div id="entry_as_team" class="form_contents">
147
- <th>ザー名:</th>
161
+ <label>名:
148
- <td><input type="text" class="form-control" placeholder="ザー名"/></td>
162
+ <input type="text" class="form-control" placeholder="名"/>
149
- </tr>
163
+ </label>
150
- <tr id="entry_select_team">
151
- <th>チーム名:</th>
152
- <td>
164
+ <label>ユーザ名:
153
- <select class="custom-select">
165
+ <select class="custom-select">
154
- <option selected>選択</option>
166
+ <option selected>ザー選択</option>
155
- <option value="1">A-team</option>
167
+ <option value="1">User-A</option>
156
- <option value="2">B-team</option>
168
+ <option value="2">User-B</option>
157
- <option value="3">C-team</option>
169
+ <option value="3">User-C</option>
158
- <option value="4">D-team</option>
170
+ <option value="4">User-D</option>
159
- <option value="5">E-team</option>
171
+ <option value="5">User-E</option>
160
- </select>
172
+ </select>
161
- </td>
162
- </tr>
163
- <tr>
164
- <!-- <p>紹介された方のお名前を入力してください。</p></td> -->
165
- </tr>
166
- <tr id="entry_input_team">
167
- <th>チーム名:</th>
168
- <td><input type="text" class="form-control" placeholder="チーム名"/></td>
169
- </tr>
170
- <tr id="entry_select_user">
171
- <th>ユーザー名:</th>
172
- <td>
173
- <select class="custom-select">
174
- <option selected>ユーザー選択</option>
175
- <option value="1">User-A</option>
176
- <option value="2">User-B</option>
177
- <option value="3">User-C</option>
178
- <option value="4">User-D</option>
179
- <option value="5">User-E</option>
180
- </select>
181
- </td>
182
- </tr>
183
- <tr>
184
- <!-- <p>紹介された方のお名前を入力してください。</p></td> -->
185
- </tr>
186
- </table>
173
+ </label>
174
+ <button type="submit">SUBMIT_B</button>
175
+ </div>
187
176
  </form>
188
177
 
189
178
  <!--スクリプト-->
190
179
  <script type="text/javascript">
191
180
  function entryChange1(){
192
- var iu = document.getElementById('entry_input_user');
181
+ var eau = document.getElementById('entry_as_user');
193
- var st = document.getElementById('entry_select_team');
194
- var it = document.getElementById('entry_input_team');
182
+ var eat = document.getElementById('entry_as_team');
195
- var su = document.getElementById('entry_select_user');
183
+
196
-
197
184
  radio = document.getElementsByName('entryPlan')
198
185
  if(radio[0].checked) {
199
186
  //フォーム
200
- iu.style.display = "";
187
+ eau.style.display = "";
201
- st.style.display = "";
202
- it.style.display = "none";
188
+ eat.style.display = "none";
203
- su.style.display = "none";
204
189
  //特典
205
190
  //document.getElementById('firstNotice').style.display = "";
206
191
  }else if(radio[1].checked) {
207
192
  //フォーム
208
- iu.style.display = "none";
193
+ eau.style.display = "none";
209
- st.style.display = "none";
210
- it.style.display = "";
194
+ eat.style.display = "";
211
- su.style.display = "";
212
195
  //特典
213
196
  //document.getElementById('firstNotice').style.display = "none";
214
197
  }
@@ -217,4 +200,9 @@
217
200
  //オンロードさせ、リロード時に選択を保持
218
201
  window.onload = entryChange1;
219
202
  </script>
203
+ ```
204
+ ```css
205
+ .form_contents >label{
206
+ display: block;
207
+ }
220
208
  ```

6

追記

2018/08/29 16:53

投稿

liveasnotes
liveasnotes

スコア1284

answer CHANGED
@@ -120,4 +120,101 @@
120
120
  //オンロードさせ、リロード時に選択を保持
121
121
  window.onload = entryChange1;
122
122
  </script>
123
+ ```
124
+
125
+ # 追記(20180829)
126
+ これでどうでしょう.
127
+ 単順に,いじりたい要素にidを振り分けて操作しているだけですが
128
+ ![イメージ説明](4ff916dad21f42c3c85b149ead61b516.gif)
129
+
130
+ ```html
131
+ <form class="form-control" action="./score" method="post">
132
+ <table class="layout-set" border="0" cellspacing="0" cellpadding="0">
133
+ <tr>
134
+ <th>登録種別</th>
135
+ <td>
136
+ <label>
137
+ <input type="radio" name="entryPlan" value="hoge1" onclick="entryChange1();" checked="checked" />
138
+ ユーザー
139
+ </label>
140
+ <label>
141
+ <input type="radio" name="entryPlan" value="hoge2" onclick="entryChange1();" />
142
+ チーム
143
+ </label>
144
+ </td>
145
+ </tr>
146
+ <tr id="entry_input_user">
147
+ <th>ユーザー名:</th>
148
+ <td><input type="text" class="form-control" placeholder="ユーザー名"/></td>
149
+ </tr>
150
+ <tr id="entry_select_team">
151
+ <th>チーム名:</th>
152
+ <td>
153
+ <select class="custom-select">
154
+ <option selected>チーム選択</option>
155
+ <option value="1">A-team</option>
156
+ <option value="2">B-team</option>
157
+ <option value="3">C-team</option>
158
+ <option value="4">D-team</option>
159
+ <option value="5">E-team</option>
160
+ </select>
161
+ </td>
162
+ </tr>
163
+ <tr>
164
+ <!-- <p>紹介された方のお名前を入力してください。</p></td> -->
165
+ </tr>
166
+ <tr id="entry_input_team">
167
+ <th>チーム名:</th>
168
+ <td><input type="text" class="form-control" placeholder="チーム名"/></td>
169
+ </tr>
170
+ <tr id="entry_select_user">
171
+ <th>ユーザー名:</th>
172
+ <td>
173
+ <select class="custom-select">
174
+ <option selected>ユーザー選択</option>
175
+ <option value="1">User-A</option>
176
+ <option value="2">User-B</option>
177
+ <option value="3">User-C</option>
178
+ <option value="4">User-D</option>
179
+ <option value="5">User-E</option>
180
+ </select>
181
+ </td>
182
+ </tr>
183
+ <tr>
184
+ <!-- <p>紹介された方のお名前を入力してください。</p></td> -->
185
+ </tr>
186
+ </table>
187
+ </form>
188
+
189
+ <!--スクリプト-->
190
+ <script type="text/javascript">
191
+ function entryChange1(){
192
+ var iu = document.getElementById('entry_input_user');
193
+ var st = document.getElementById('entry_select_team');
194
+ var it = document.getElementById('entry_input_team');
195
+ var su = document.getElementById('entry_select_user');
196
+
197
+ radio = document.getElementsByName('entryPlan')
198
+ if(radio[0].checked) {
199
+ //フォーム
200
+ iu.style.display = "";
201
+ st.style.display = "";
202
+ it.style.display = "none";
203
+ su.style.display = "none";
204
+ //特典
205
+ //document.getElementById('firstNotice').style.display = "";
206
+ }else if(radio[1].checked) {
207
+ //フォーム
208
+ iu.style.display = "none";
209
+ st.style.display = "none";
210
+ it.style.display = "";
211
+ su.style.display = "";
212
+ //特典
213
+ //document.getElementById('firstNotice').style.display = "none";
214
+ }
215
+ }
216
+
217
+ //オンロードさせ、リロード時に選択を保持
218
+ window.onload = entryChange1;
219
+ </script>
123
220
  ```

5

修正

2018/08/29 04:34

投稿

liveasnotes
liveasnotes

スコア1284

answer CHANGED
@@ -30,13 +30,15 @@
30
30
  ちょうど開発者ツールのように,タグの入れ子構造を記述することで,閉じタグ忘れや不要な開始タグを見つけやすくなります.あと,Web開発向けのエディタ(AtomやBrackets,VSCodeなど)は,構文エラーの有無を教えてくれます.使ってみてください.
31
31
 
32
32
  ---
33
- idを振るべきタグは下のタグのようです(これも,インデントを整えておけばすぐ分かる)
33
+ ~~idを振るべきタグは下のタグのようです(これも,インデントを整えておけばすぐ分かる)~~
34
+ うっかりしていました(汗)
35
+ liveweaveのリントがはくエラーを消そうとしてこう書きましたが,x_xさんのご指摘の通り,tr要素の直下にtr要素は書けないです.つまり,下のgifのようにやるのは間違いになります
34
36
  ![イメージ説明](5566c19d4efcae70aafa54dbf0128271.gif)
37
+
38
+ 修正版:
35
39
  ```html
36
- <!--インデント整えたバージョン-->
40
+ <!--整えたバージョン-->
37
41
 
38
- <!--インデント整えたバージョン-->
39
-
40
42
  <form class="form-control" action="./score" method="post">
41
43
  <table class="layout-set" border="0" cellspacing="0" cellpadding="0">
42
44
  <tr>

4

修正

2018/08/29 03:31

投稿

liveasnotes
liveasnotes

スコア1284

answer CHANGED
@@ -35,71 +35,87 @@
35
35
  ```html
36
36
  <!--インデント整えたバージョン-->
37
37
 
38
+ <!--インデント整えたバージョン-->
39
+
38
40
  <form class="form-control" action="./score" method="post">
39
- <table class="layout-set" border="0" cellspacing="0" cellpadding="0">
41
+ <table class="layout-set" border="0" cellspacing="0" cellpadding="0">
40
- <tr>
42
+ <tr>
41
- <th>登録種別</th>
43
+ <th>登録種別</th>
42
- <td>
44
+ <td>
43
- <label>
45
+ <label>
44
- <input type="radio" name="entryPlan" value="hoge1" onclick="entryChange1();" checked="checked" />
46
+ <input type="radio" name="entryPlan" value="hoge1" onclick="entryChange1();" checked="checked" />
45
- ユーザー
47
+ ユーザー
46
- </label>
48
+ </label>
47
- <label>
49
+ <label>
48
- <input type="radio" name="entryPlan" value="hoge2" onclick="entryChange1();" />
50
+ <input type="radio" name="entryPlan" value="hoge2" onclick="entryChange1();" />
49
- チーム
51
+ チーム
50
- </label>
52
+ </label>
51
- </td>
53
+ </td>
52
- </tr>
54
+ </tr>
53
- <!-- 表示非表示切り替え -->
55
+ <!-- 表示非表示切り替え -->
54
- <tr><!-- ←追加分-->
55
- <tr id="firstBox">
56
+ <tr id="firstBox">
56
- <!--<tr> ←削除分-->
57
+ <!--<tr> ←削除分-->
57
- <th>ユーザー名:</th>
58
+ <th>ユーザー名:</th>
58
- <td><input type="text" class="form-control" placeholder="ユーザー名"/></td>
59
+ <td><input type="text" class="form-control" placeholder="ユーザー名"/></td>
59
- </tr>
60
+ </tr>
60
- <tr>
61
+ <tr>
61
- <th>チーム名:</th>
62
+ <th>チーム名:</th>
62
- <td>
63
+ <td>
63
- <select class="custom-select">
64
+ <select class="custom-select">
64
- <option selected>チーム選択</option>
65
+ <option selected>チーム選択</option>
65
- <option value="1">A-team</option>
66
+ <option value="1">A-team</option>
66
- <option value="2">B-team</option>
67
+ <option value="2">B-team</option>
67
- <option value="3">C-team</option>
68
+ <option value="3">C-team</option>
68
- <option value="4">D-team</option>
69
+ <option value="4">D-team</option>
69
- <option value="5">E-team</option>
70
+ <option value="5">E-team</option>
70
- </select>
71
+ </select>
71
- </td>
72
+ </td>
72
- <!-- <p>紹介された方のお名前を入力してください。</p></td> -->
73
+ <!-- <p>紹介された方のお名前を入力してください。</p></td> -->
73
- </tr>
74
+ </tr>
75
+ <!-- 表示非表示切り替え -->
76
+ <tr id="secondBox">
77
+ <!--<tr> ←削除分-->
78
+ <th>チーム名:</th>
79
+ <td><input type="text" class="form-control" placeholder="チーム名"/></td>
74
- </tr>
80
+ </tr>
75
- <!-- 表示非表示切り替え -->
81
+ <tr>
76
- <tr id="secondBox">
77
- <th>名:</th>
82
+ <th>ザー名:</th>
83
+ <td>
84
+ <select class="custom-select">
85
+ <option selected>ユーザー選択</option>
86
+ <option value="1">User-A</option>
87
+ <option value="2">User-B</option>
88
+ <option value="3">User-C</option>
89
+ <option value="4">User-D</option>
90
+ <option value="5">User-E</option>
91
+ </select>
92
+ </td>
78
- <td><input type="text" class="form-control" placeholder="チーム"/></td>
93
+ <!-- <p>紹介された方のお前を入力してください。</p></td> -->
79
- </tr>
94
+ </tr>
95
+
80
- </table>
96
+ </table>
81
97
  </form>
82
98
 
83
99
  <!--スクリプト-->
84
100
  <script type="text/javascript">
85
- function entryChange1(){
101
+ function entryChange1(){
86
- radio = document.getElementsByName('entryPlan')
102
+ radio = document.getElementsByName('entryPlan')
87
- if(radio[0].checked) {
103
+ if(radio[0].checked) {
88
- //フォーム
104
+ //フォーム
89
- document.getElementById('firstBox').style.display = "";
105
+ document.getElementById('firstBox').style.display = "";
90
- document.getElementById('secondBox').style.display = "none";
106
+ document.getElementById('secondBox').style.display = "none";
91
- //特典
107
+ //特典
92
- //document.getElementById('firstNotice').style.display = "";
108
+ //document.getElementById('firstNotice').style.display = "";
93
- }else if(radio[1].checked) {
109
+ }else if(radio[1].checked) {
94
- //フォーム
110
+ //フォーム
95
- document.getElementById('firstBox').style.display = "none";
111
+ document.getElementById('firstBox').style.display = "none";
96
- document.getElementById('secondBox').style.display = "";
112
+ document.getElementById('secondBox').style.display = "";
97
- //特典
113
+ //特典
98
- //document.getElementById('firstNotice').style.display = "none";
114
+ //document.getElementById('firstNotice').style.display = "none";
99
- }
100
115
  }
116
+ }
101
117
 
102
- //オンロードさせ、リロード時に選択を保持
118
+ //オンロードさせ、リロード時に選択を保持
103
- window.onload = entryChange1;
119
+ window.onload = entryChange1;
104
120
  </script>
105
121
  ```

3

追記

2018/08/29 03:26

投稿

liveasnotes
liveasnotes

スコア1284

answer CHANGED
@@ -31,4 +31,75 @@
31
31
 
32
32
  ---
33
33
  idを振るべきタグは下のタグのようです(これも,インデントを整えておけばすぐ分かる)
34
- ![イメージ説明](5566c19d4efcae70aafa54dbf0128271.gif)
34
+ ![イメージ説明](5566c19d4efcae70aafa54dbf0128271.gif)
35
+ ```html
36
+ <!--インデント整えたバージョン-->
37
+
38
+ <form class="form-control" action="./score" method="post">
39
+ <table class="layout-set" border="0" cellspacing="0" cellpadding="0">
40
+ <tr>
41
+ <th>登録種別</th>
42
+ <td>
43
+ <label>
44
+ <input type="radio" name="entryPlan" value="hoge1" onclick="entryChange1();" checked="checked" />
45
+ ユーザー
46
+ </label>
47
+ <label>
48
+ <input type="radio" name="entryPlan" value="hoge2" onclick="entryChange1();" />
49
+ チーム
50
+ </label>
51
+ </td>
52
+ </tr>
53
+ <!-- 表示非表示切り替え -->
54
+ <tr><!-- ←追加分-->
55
+ <tr id="firstBox">
56
+ <!--<tr> ←削除分-->
57
+ <th>ユーザー名:</th>
58
+ <td><input type="text" class="form-control" placeholder="ユーザー名"/></td>
59
+ </tr>
60
+ <tr>
61
+ <th>チーム名:</th>
62
+ <td>
63
+ <select class="custom-select">
64
+ <option selected>チーム選択</option>
65
+ <option value="1">A-team</option>
66
+ <option value="2">B-team</option>
67
+ <option value="3">C-team</option>
68
+ <option value="4">D-team</option>
69
+ <option value="5">E-team</option>
70
+ </select>
71
+ </td>
72
+ <!-- <p>紹介された方のお名前を入力してください。</p></td> -->
73
+ </tr>
74
+ </tr>
75
+ <!-- 表示非表示切り替え -->
76
+ <tr id="secondBox">
77
+ <th>チーム名:</th>
78
+ <td><input type="text" class="form-control" placeholder="チーム名"/></td>
79
+ </tr>
80
+ </table>
81
+ </form>
82
+
83
+ <!--スクリプト-->
84
+ <script type="text/javascript">
85
+ function entryChange1(){
86
+ radio = document.getElementsByName('entryPlan')
87
+ if(radio[0].checked) {
88
+ //フォーム
89
+ document.getElementById('firstBox').style.display = "";
90
+ document.getElementById('secondBox').style.display = "none";
91
+ //特典
92
+ //document.getElementById('firstNotice').style.display = "";
93
+ }else if(radio[1].checked) {
94
+ //フォーム
95
+ document.getElementById('firstBox').style.display = "none";
96
+ document.getElementById('secondBox').style.display = "";
97
+ //特典
98
+ //document.getElementById('firstNotice').style.display = "none";
99
+ }
100
+ }
101
+
102
+ //オンロードさせ、リロード時に選択を保持
103
+ window.onload = entryChange1;
104
+ </script>
105
+ ```

2

追記

2018/08/28 15:43

投稿

liveasnotes
liveasnotes

スコア1284

answer CHANGED
File without changes

1

追記

2018/08/28 15:42

投稿

liveasnotes
liveasnotes

スコア1284

answer CHANGED
@@ -27,4 +27,8 @@
27
27
  開発者ツールの開き方・使い方はOS・ブラウザによって微妙に違うので,詳しいやり方はご自身で調べてみてください.
28
28
 
29
29
  また,同様のミスを防ぐ工夫として「インデントを整える」ことをおすすめします.
30
- ちょうど開発者ツールのように,タグの入れ子構造を記述することで,閉じタグ忘れや不要な開始タグを見つけやすくなります.あと,Web開発向けのエディタ(AtomやBrackets,VSCodeなど)は,構文エラーの有無を教えてくれます.使ってみてください.
30
+ ちょうど開発者ツールのように,タグの入れ子構造を記述することで,閉じタグ忘れや不要な開始タグを見つけやすくなります.あと,Web開発向けのエディタ(AtomやBrackets,VSCodeなど)は,構文エラーの有無を教えてくれます.使ってみてください.
31
+
32
+ ---
33
+ idを振るべきタグは下のタグのようです(これも,インデントを整えておけばすぐ分かる)
34
+ ![イメージ説明](5566c19d4efcae70aafa54dbf0128271.gif)