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

質問編集履歴

1

ご指摘いただいたようにコードを修正いたしました。

2020/12/22 07:21

投稿

20200713
20200713

スコア16

title CHANGED
File without changes
body CHANGED
@@ -7,6 +7,7 @@
7
7
  ### 該当のソースコード
8
8
 
9
9
  ```html
10
+ 修正前
10
11
  <form name="form1">
11
12
  <input checked type="checkbox" id="check1" onClick="displayTR_checkbox(this,'tr1');"><label for="check1">tr1</label><br>
12
13
     <input checked type="checkbox" id="check2" onClick="displayTR_checkbox(this,'tr2');"><label for="check2">tr2</label>
@@ -24,8 +25,28 @@
24
25
  </tr>
25
26
  </table>
26
27
  </form>
28
+
29
+ 修正後
30
+ <form name="form1">
31
+ <input checked type="checkbox" id="check1" onClick="displayTR_checkbox('check1','tr1');"><label for="check1">tr1</label><br>
32
+ <input checked type="checkbox" id="check2" onClick="displayTR_checkbox('check2','tr2');"><label for="check2">tr2</label>
33
+
34
+ <table class="picTable">
35
+ <tr id="tr1">
36
+ <td><img src="http://placehold.jp/150x150.png"></td>
37
+ <td><img src="http://placehold.jp/150x150.png"></td>
38
+ <td><img src="http://placehold.jp/150x150.png"></td>
39
+ </tr>
40
+ <tr id="tr2">
41
+ <td><img src="http://placehold.jp/150x150.png"></td>
42
+ <td><img src="http://placehold.jp/150x150.png"></td>
43
+ <td><img src="http://placehold.jp/150x150.png"></td>
44
+ </tr>
45
+ </table>
46
+ </form>
27
47
  ```
28
48
  ```javascript
49
+ 修正前
29
50
  function displayTR_checkbox(this,trID){
30
51
  var TR = document.getElementById(trID);
31
52
  if(checkbox.checked = false){
@@ -34,6 +55,16 @@
34
55
  TR.style.display = block;
35
56
  }
36
57
  }
58
+ 修正後
59
+ function displayTR_checkbox(checkboxID,trID){
60
+ var TR = document.getElementById(trID);
61
+ var Checkbox = document.getElementById(checkboxID);
62
+ if(! Checkbox.checked){
63
+ TR.style.display = '';
64
+ } else {
65
+ TR.style.display = 'none';
66
+ }
67
+ }
37
68
  ```
38
69
 
39
70