JS-History-Recoder 2
by homura0731
HTML
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js"></script>
<button id="prev2" type="button">上一步</button>
<button id="next2" type="button">下一步</button>
<br><br>
<textarea id="text2" cols="5" style="width:300px"></textarea>
JavaScript
var step2 = 0; // 步驟變數
var textList2 = new Array(); // array容器
var prev2 = document.getElementById('prev2');
var next2 = document.getElementById('next2');
var text2 = document.getElementById('text2');
function textWrite2(){
step2++;
textList2.push(text2.value);
}
var debounce = _.debounce(textWrite2, 500);// 延遲500毫秒紀錄
text2.addEventListener('input', debounce);// 改成監聽延遲函數
prev2.onclick = function(){
if(step2 < 2){
alert('沒有上一步');
}else{
step2--;
text2.value = textList2[step2 - 1];
}
}
next2.onclick = function(){
if(step2 > textList2.length - 1){
alert('沒有下一步');
}else{
step2++;
text2.value = textList2[step2 - 1];
}
}