File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 8
8
</ head >
9
9
< body >
10
10
< button onclick ="clickfun() "> CLICK ME!</ button >
11
+ < button disabled id ="cancel " onclick ="cancel() "> CANCEL</ button >
11
12
< button onclick ="otherfun() "> OTHER!</ button >
12
13
< div id ="res "> </ div >
13
14
< div id ="count "> </ div >
14
15
< script >
15
16
let count = 0
17
+ let taskId = null ;
16
18
function clickfun ( ) {
17
19
// let start = new Date().getTime()
18
20
21
23
// }
22
24
// document.getElementById('res').innerText = 'HELLO'
23
25
24
- setTimeout ( ( ) => {
26
+ taskId = setTimeout ( ( ) => {
25
27
document . getElementById ( 'res' ) . innerText = 'HELLO'
28
+ document . getElementById ( 'cancel' ) . setAttribute ( 'disabled' , true )
26
29
} , 5000 )
27
30
31
+ document . getElementById ( 'cancel' ) . removeAttribute ( 'disabled' )
32
+
33
+ }
34
+
35
+ function cancel ( ) {
36
+ if ( taskId ) {
37
+ clearTimeout ( taskId )
38
+ document . getElementById ( 'cancel' ) . setAttribute ( 'disabled' , true )
39
+ }
28
40
}
29
41
30
42
function otherfun ( ) {
You can’t perform that action at this time.
0 commit comments