我可以使用execCommand undo来撤消未使用execCommand执行的操作吗?

时间:2014-04-08 14:53:46

标签: javascript html google-chrome undo-redo execcommand

我正在尝试使用execCommand实现一个WYSIWYG编辑器(我知道很多WYSIWYG编辑器都存在,但它们对我来说都不够好)。现在,一切正常,但如果我尝试使用backColor命令,它似乎不起作用。

我想做的只是在元素上设置背景CSS,并以某种方式将其添加到撤消/重做队列,因此 Ctrl + Z 将更改回自定义更改。

随处可做吗?或者我只限于撤消/重做执行命令?

我只对Chrome解决方案感兴趣,IE&不支持FF。

1 个答案:

答案 0 :(得分:0)

我的anwser可能不是最漂亮的,但请求很好:)

我用过

var undo = []; // array
var redo = [];
// to store the undo and redo data
// and added event listener to textarea

document.getElementById("textarea").oninput = function(){
    // do something
}

http://jsfiddle.net/7z6kow73/1/

相关问题