Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 18:01:14
Original
1386 people have browsed it

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 ]
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template