回答編集履歴

1

調整

2025/04/14 01:25

投稿

yambejp
yambejp

スコア117548

test CHANGED
@@ -83,3 +83,83 @@
83
83
  <button id="reset">リセット</button>
84
84
  </div>
85
85
  ```
86
+
87
+ # jQuery版
88
+ 上記書き直すとこう
89
+ ```html
90
+ <style>
91
+ table{
92
+ text-align: center;
93
+ margin-bottom:30px;
94
+ }
95
+ .done:not(.active){
96
+ background-Color:lightgray;
97
+ }
98
+ .active{
99
+ background-Color:#DF543A;
100
+ }
101
+ </style>
102
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
103
+ <script>
104
+ $(function(){
105
+ let timerId;
106
+ const setButtons=(start,stop,reset)=>{
107
+ $('#start').prop('disabled',start);
108
+ $('#stop').prop('disabled',stop);
109
+ $('#reset').prop('disabled',reset);
110
+ };
111
+ setButtons(false,true,true);
112
+ $('#start').on('click',()=>{
113
+ $('.active').removeClass('active');
114
+ const select=$('td:not(.done)');
115
+ setButtons(true,false,true);
116
+ timerId=setInterval(()=>{
117
+ const n=Math.floor(Math.random()*select.length);
118
+ $('.active').removeClass('active');
119
+ select.eq(n).addClass('active');
120
+ },100);
121
+ });
122
+ $('#stop').on('click',()=>{
123
+ $('.active').addClass('done');
124
+ const select=$('td:not(.done)');
125
+ setButtons(select.length===0,true,false);
126
+ clearInterval(timerId);
127
+ });
128
+ $('#reset').on('click',()=>{
129
+ setButtons(false,true,true);
130
+ $('.active,.done').removeClass('active done');
131
+ });
132
+ });
133
+ </script>
134
+ <table border>
135
+ <tr>
136
+ <td>1</td>
137
+ <td>2</td>
138
+ <td>3</td>
139
+ <td>4</td>
140
+ </tr>
141
+ <tr>
142
+ <td>5</td>
143
+ <td>6</td>
144
+ <td>7</td>
145
+ <td>8</td>
146
+ </tr>
147
+ <tr>
148
+ <td>9</td>
149
+ <td>10</td>
150
+ <td>11</td>
151
+ <td>12</td>
152
+ </tr>
153
+ <tr>
154
+ <td>13</td>
155
+ <td>14</td>
156
+ <td>15</td>
157
+ <td>16</td>
158
+ </tr>
159
+ </table>
160
+ <div id="button">
161
+ <button id="start">スタート</button>
162
+ <button id="stop">ストップ</button>
163
+ <button id="reset">リセット</button>
164
+ </div>
165
+ ```