监听Ueditor的 iframe中的按键,按键组合事件(Ctrl+s)
个人博客 地址:https://www.wenhaofan.com/a/20190716214214
监听按键事件
ueditor.ready(function() { UE.dom.domUtils.on(ueditor.body,"keydown",function(oEvent){ var oEvent = oEvent || window.oEvent; //获取键盘的keyCode值 var nKeyCode = oEvent.keyCode || oEvent.which || oEvent.charCode; //do something }); }
监听按键组合事件(Ctrl+s)
ueditor.ready(function() { UE.dom.domUtils.on(ueditor.body,"keydown",function(oEvent){ var oEvent = oEvent || window.oEvent; //获取键盘的keyCode值 var nKeyCode = oEvent.keyCode || oEvent.which || oEvent.charCode; //获取ctrl 键对应的事件属性 var bCtrlKeyCode = oEvent.ctrlKey || oEvent.metaKey; if( nKeyCode == 83 && bCtrlKeyCode ) { //do something //阻止触发默认的ctrl+s事件 oEvent.returnValue = false; } }); }
注意
1.监听事件需要在ueditor.ready回调中执行,因为绑定监听时需要获取到ueditor.body对象,该对象在ueditor初始化完成后才能获取到。
2.ueditor为Ueditor创建后返回的实例对象