回答編集履歴

1

調整

2017/06/12 14:17

投稿

yambejp
yambejp

スコア115010

test CHANGED
@@ -3,3 +3,107 @@
3
3
 
4
4
 
5
5
  var index=$('.btn').index(this);
6
+
7
+
8
+
9
+ # 調整
10
+
11
+
12
+
13
+ ```javascript
14
+
15
+ $(function(){
16
+
17
+ $('#t1 tbody tr')
18
+
19
+ .has('td.danger').append($('<td>').append($('<button>').addClass("btn btn-sm").text('表示'))).end()
20
+
21
+ .not(':has(td.danger)').append($('<td>').text('no danger'));
22
+
23
+ $('#t1').on('click','.btn',function(){
24
+
25
+ var n=$(this).closest('tr').find('td.danger');
26
+
27
+ if(n.hasClass('height')){ console.log('height');}
28
+
29
+ if(n.hasClass('weight')){ console.log('weight');}
30
+
31
+ });
32
+
33
+ });
34
+
35
+
36
+
37
+
38
+
39
+ ```
40
+
41
+
42
+
43
+ ```HTML
44
+
45
+ <table id="t1">
46
+
47
+ <thead>
48
+
49
+ <tr>
50
+
51
+ <th>名前</th>
52
+
53
+ <th>身長</th>
54
+
55
+ <th>体重</th>
56
+
57
+ <th></th>
58
+
59
+ </tr>
60
+
61
+ </thead>
62
+
63
+ <tbody>
64
+
65
+ <tr>
66
+
67
+ <td>佐藤</td>
68
+
69
+ <td class="height">170</td>
70
+
71
+ <td class="weight danger">50</td>
72
+
73
+ </tr>
74
+
75
+ <tr>
76
+
77
+ <td>鈴木</td>
78
+
79
+ <td class="danger height">150</td>
80
+
81
+ <td class="weight">50</td>
82
+
83
+ </tr>
84
+
85
+ <tr>
86
+
87
+ <td>田中</td>
88
+
89
+ <td class="height">180</td>
90
+
91
+ <td class="weight">70</td>
92
+
93
+ </tr>
94
+
95
+ <tr>
96
+
97
+ <td>山田</td>
98
+
99
+ <td class="height">170</td>
100
+
101
+ <td class="weight danger">80</td>
102
+
103
+ </tr>
104
+
105
+ </tbody>
106
+
107
+ </table>
108
+
109
+ ```