回答編集履歴
2
追記
answer
CHANGED
@@ -23,4 +23,56 @@
|
|
23
23
|
$('tr:nth-of-type(1)').css('backgroundColor', 'gray');
|
24
24
|
```
|
25
25
|
|
26
|
-
と言った感じですかね?
|
26
|
+
と言った感じですかね?
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
# 追記
|
31
|
+
|
32
|
+
```
|
33
|
+
<script src="https://code.jquery.com/jquery-3.2.1.js" integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" crossorigin="anonymous"></script>
|
34
|
+
|
35
|
+
<table>
|
36
|
+
<tr class="staff">
|
37
|
+
<td>1</td><td>A</td><td>AA</td><td>AAA</td><td>AAAA</td>
|
38
|
+
</tr>
|
39
|
+
|
40
|
+
<tr class="staff">
|
41
|
+
<td>2</td><td>B</td><td>BB</td><td>BBB</td><td>BBBB</td>
|
42
|
+
</tr>
|
43
|
+
|
44
|
+
<tr class="staff">
|
45
|
+
<td>3</td><td>C</td><td>CC</td><td>CCC</td><td>CCCC</td>
|
46
|
+
</tr>
|
47
|
+
</table>
|
48
|
+
|
49
|
+
|
50
|
+
<script>
|
51
|
+
$(function(){
|
52
|
+
$('tr:nth-of-type(1)').css('backgroundColor', 'gray');
|
53
|
+
|
54
|
+
// 1列目の色を解除
|
55
|
+
setOff(1);
|
56
|
+
|
57
|
+
// 2列目に色を付けてみる
|
58
|
+
setOn(2);
|
59
|
+
});
|
60
|
+
|
61
|
+
|
62
|
+
// こいつかな?
|
63
|
+
function setOn(num){
|
64
|
+
// 指定した列の色を変える
|
65
|
+
$('tr:nth-of-type('+ num +')').css('backgroundColor', 'gray');
|
66
|
+
}
|
67
|
+
|
68
|
+
|
69
|
+
// ついで
|
70
|
+
function setOff(num){
|
71
|
+
// 指定した列の色を元に戻す
|
72
|
+
$('tr:nth-of-type('+ num +')').css('backgroundColor', '');
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
</script>
|
77
|
+
|
78
|
+
```
|
1
JSのミス修正
answer
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
`:nth-of-type(n)`だというものが使えそうな気がします。
|
21
21
|
|
22
22
|
```
|
23
|
-
$('
|
23
|
+
$('tr:nth-of-type(1)').css('backgroundColor', 'gray');
|
24
24
|
```
|
25
25
|
|
26
26
|
と言った感じですかね?
|