I ran into a task, I know JS rather badly, I need the function to handle the cancel button on the form, transfer from JQuery to JavaScript
Closed due to the fact that off-topic participants Regent , Komdosh , Igor , 0xdb , aleksandr barakin January 8 at 13:39 .
It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:
- " Learning tasks are allowed as questions only on the condition that you tried to solve them yourself before asking a question . Please edit the question and indicate what caused you difficulties in solving the problem. For example, give the code you wrote, trying to solve the problem "- Regent, Komdosh, Igor, 0xdb, aleksandr barakin
|
1 answer
var states = ['', ]; var inputArea = document.querySelector("#inputarea"); var undoBtn = document.querySelector("#undo"); inputArea.addEventListener('input', function() { var str = inputArea.value; states.push(str); }); inputarea.value = ""; undoBtn.addEventListener('click', function() { if (states.length === 1) { return false; } else { states.length = states.length - 1; inputArea.value = states[states.length - 1]; } }) <button id="undo"> Undo </button> <textarea id="inputarea"> </textarea> |