Home  >  Article  >  Web Front-end  >  Based on jQuery, let textarea support Ctrl Z step-by-step undo function_jquery

Based on jQuery, let textarea support Ctrl Z step-by-step undo function_jquery

WBOY
WBOYOriginal
2016-05-16 18:01:141356browse

There is relatively little code.
The main ones are:

Copy code The code is as follows:

var log = [] ;
$(function () {
var txt = window.setInterval(function () {
if (log[log.length - 1] != $("#t").val() ) {
log[log.length] = $("#t").val();
}
}, 1500);
var isCtrl = false;
$(document ).keydown(function (e) {
if (e.which === 17)
isCtrl = true;
if (e.which === 90 && isCtrl === true) {
log.pop();
$("#t").val(log[log.length - 1]).blur();
}
}).keyup(function (e ) {
if (e.which === 17)
isCtrl = false;
});
});

Demo code:

[Ctrl A select all Note:
If you need to introduce external Js, you need to refresh to execute ]
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn