nicEdit:向编辑器添加键(按|向上|向下)事件

Sim*_*ult 4 javascript nicedit

我使用nicEdit有一个RTF文本区域,我需要添加一个onkeypress,onkeyuponkeydown事件.

我像这样创建我的实例:

var emailRtf = new nicEditor({  iconsPath : 'nicEdit/nicEditorIcons.gif', 
    buttonList : ['bold','italic','underline','fontSize','forecolor','ol','ul','link','unlink','removeformat'],
    maxHeight: 600}).panelInstance('REPLY_MESSAGE');
Run Code Online (Sandbox Code Playgroud)

我尝试了以下(with keypress,keydownand keyup):

emailRtf.addEvent("keypress", function() { alert('test') }); // Not working
emailRtf.addEvent("keypress", function(evt) { alert('test') }); // Not working
Run Code Online (Sandbox Code Playgroud)

但是,以下工作:

emailRtf.addEvent("blur", function() { alert('test') }); // Alert shows when I leave focus on the textArea
Run Code Online (Sandbox Code Playgroud)

如何添加key(press|up|down)到nicEdit编辑器?

注意:我的页面中有多个RTF textarea实例,我需要将key(press|down|up)事件添加到一个.我发现了这个问题,它在所有实例上添加了事件.另外,我想保留nicEdit.js完好无损.

小智 5

看一下这里限制WYSIWYG编辑器中的字符数(NicEdit)

它应该在没有更改nicedit.js的情况下工作

$("div.nicEdit-main").keyup(function () { });
Run Code Online (Sandbox Code Playgroud)

看看jsfiddle http://jsfiddle.net/jGLRn/15/

  • 作品!没有jQuery:`document.getElementById('REPLY_MESSAGE').parentElement.onkeypress = function(){alert('key pressed!'); };` (2认同)