回答編集履歴
3
よくある
test
CHANGED
@@ -35,3 +35,69 @@
|
|
35
35
|
</form>
|
36
36
|
|
37
37
|
```
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
# interval処理
|
42
|
+
|
43
|
+
```javascript
|
44
|
+
|
45
|
+
<script>
|
46
|
+
|
47
|
+
var timerId;
|
48
|
+
|
49
|
+
window.addEventListener('DOMContentLoaded', ()=>{
|
50
|
+
|
51
|
+
document.querySelector('#words').addEventListener('click',e=>{
|
52
|
+
|
53
|
+
var btn=e.target;
|
54
|
+
|
55
|
+
btn.disabled=true;
|
56
|
+
|
57
|
+
var msg = document.querySelector("#message").value.split("");
|
58
|
+
|
59
|
+
var box= document.querySelector("#box");
|
60
|
+
|
61
|
+
box.textContent="";
|
62
|
+
|
63
|
+
var len1= msg.length;
|
64
|
+
|
65
|
+
clearInterval(timerId);
|
66
|
+
|
67
|
+
timerId=setInterval((function hoge(){
|
68
|
+
|
69
|
+
var len2= box.textContent.length;
|
70
|
+
|
71
|
+
if(len1<=len2){
|
72
|
+
|
73
|
+
clearInterval(timerId);
|
74
|
+
|
75
|
+
btn.disabled=false;
|
76
|
+
|
77
|
+
}else{
|
78
|
+
|
79
|
+
box.textContent+=msg[len2];
|
80
|
+
|
81
|
+
return hoge;
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
})(),500);
|
86
|
+
|
87
|
+
});
|
88
|
+
|
89
|
+
});
|
90
|
+
|
91
|
+
</script>
|
92
|
+
|
93
|
+
<form>
|
94
|
+
|
95
|
+
<input type="text" id="message">
|
96
|
+
|
97
|
+
<input type="button" id="words" value="1文字ずつ表示">
|
98
|
+
|
99
|
+
<div id="box"></div>
|
100
|
+
|
101
|
+
</form>
|
102
|
+
|
103
|
+
```
|
2
ちょうせい
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
document.querySelector("#box").textContent+=x;
|
16
16
|
|
17
|
-
await new Promise(resolve=>setTimeout(()=>
|
17
|
+
await new Promise(resolve=>setTimeout(()=>resolve(),2000));
|
18
18
|
|
19
19
|
};
|
20
20
|
|
1
ちょうせい
test
CHANGED
@@ -6,21 +6,17 @@
|
|
6
6
|
|
7
7
|
window.addEventListener('DOMContentLoaded', ()=>{
|
8
8
|
|
9
|
-
document.querySelector('#words').addEventListener('click',()=>{
|
9
|
+
document.querySelector('#words').addEventListener('click',async ()=>{
|
10
10
|
|
11
11
|
var msg = document.querySelector("#message").value.split("");
|
12
12
|
|
13
|
-
(as
|
13
|
+
for(var x of msg){
|
14
14
|
|
15
|
-
|
15
|
+
document.querySelector("#box").textContent+=x;
|
16
16
|
|
17
|
-
|
17
|
+
await new Promise(resolve=>setTimeout(()=>{resolve()},2000));
|
18
18
|
|
19
|
-
await new Promise(resolve=>setTimeout(()=>{resolve()},2000));
|
20
|
-
|
21
|
-
|
19
|
+
};
|
22
|
-
|
23
|
-
})();
|
24
20
|
|
25
21
|
});
|
26
22
|
|