基于jQuery的让textarea支持Ctrl+Z步步撤销功能
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;
});
});
演示代码:
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();
$("#s").val(log[log.length - 1]).blur();
}
}).keyup(function (e) {
if (e.which === 17)
isCtrl = false;
});
});
function show() {
$("#s").val("");
for (var i = 0; i
显示历史记录
按Ctrl+Z一步一步撤销
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]