Javascript 在Dijit编辑器中输入键处理

Javascript 在Dijit编辑器中输入键处理,javascript,dojo,Javascript,Dojo,我正在使用Dijit.Editor构建迷你RTE。dijit编辑器使用EnterKeyHandling插件(dijit.\u editor.plugins.EnterKeyHanling),它只负责处理P或Div中的输入键 我想扩展这个功能,添加我自己的功能来处理列表元素中的Enter键等。关于如何处理这个问题,有什么建议吗?这实际上应该相当容易 你可以采取几种方法 1) Monkey修补现有的EnterKeyHandling插件 大概是这样的: var oldFunc = dijit._edi

我正在使用Dijit.Editor构建迷你RTE。dijit编辑器使用EnterKeyHandling插件(dijit.\u editor.plugins.EnterKeyHanling),它只负责处理P或Div中的输入键


我想扩展这个功能,添加我自己的功能来处理列表元素中的Enter键等。关于如何处理这个问题,有什么建议吗?

这实际上应该相当容易

你可以采取几种方法

1) Monkey修补现有的EnterKeyHandling插件

大概是这样的:

var oldFunc = dijit._editor.plugins.EnterKeyHandling.prototype.onKeyPressed;
dijit._editor.plugins.EnterKeyHandling.prototype.onKeyPressed = function(){

// Do your stuff ...

oldFunc(arguments);

// Do your stuff ...

}
2) 创建自己的插件,使用EnterKeyHandling作为模板/基类 您只需剪切并粘贴EnterKeyHandling源代码,并为其指定自己的名称,然后使用onKeyPressed方法来完成您想要的操作

但更好的方法是将其子类化,并使用它而不是标准插件:

dojo.declare("so.MyEnterHandling", dijit._editor.plugins.EnterKeyHandling, {
  onKeyPressed: function(){
     // Do your stuff
     // Either use EnterKeyHandling.onKeyPressed() as a template, or call:
     this.super(arguments);
  }
}
然后像其他插件一样使用它:

plugins = "['so.MyEnterHandling']"
注意:代码示例尚未运行,只是输入到SO中