对于 Tinymce 4,它对我有用,
editor.on('keyup', function(e) {
alert('keyup occured');
//console.log('init event', e);
console.log('Editor contents was modified. Contents: ' + editor.getContent());
check_submit(); //another function calling
});
编辑:
请注意,keyup不会捕获所有情况。例如copy
//paste
来自而不是cut
来自menu
keyboard
如果你愿意,你可以用
editor.on('paste', function(e) {
console.debug('paste event');
});
editor.on('cut', function(e) {
console.debug('cut event');
});
注意
如果您从 tinymce 捕获cut
,paste
您可能不应该从 keyup 处理这些事件。我所做的是仅当键不是cut
&的键时才保存paste
:
/**
* MCE keyup callback, update the master model selected attribute
*
* @method tinyMCEKeyup
*/
tinyMCEKeyUp : function(e) {
console.log('tinymce:keyup');
var ctrlDown = false;
var ctrlKey = 17, vKey = 86, xKey = 88;
if ((e.ctrlKey) && (e.keyCode === vKey)) {
console.log('paste from keyboard')
/* got here. do nothing. let paste event handle this one */
return;
} else if ((e.ctrlKey) && (e.keyCode === xKey)) {
console.log('cut from keyboard')
/* got here. do nothing. let paste event handle this one */
return;
}
this.doSave();
},
并从 keyup 事件中调用此函数。这样,您将节省自己在剪切和粘贴时执行两次操作
注意很快你会发现任何style changes
发生的事情menu
都不会触发这些事件。
我仍在寻找捕捉风格变化的答案。