4

nicEditを使用してRTFテキストエリアを作成していますがonkeypressonkeyupまたはonkeydownイベントを追加する必要があります。

次のようにインスタンスを作成します。

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

私は次のことを試しました(、、keypressおよびkeydownkeyup

emailRtf.addEvent("keypress", function() { alert('test') }); // Not working
emailRtf.addEvent("keypress", function(evt) { alert('test') }); // Not working

ただし、次のように機能します。

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

key(press|up|down)nicEditエディターに追加するにはどうすればよいですか?

:ページにRTF textareaの複数のインスタンスがあり、key(press|down|up)1つだけにイベントを追加する必要があります。すべてのインスタンスにイベントを追加するこの質問を見つけました。また、nicEdit.jsはそのままにしておきたいと思います。

4

4 に答える 4

5

こちらをご覧くださいWYSIWYGエディターの文字数を制限する(NicEdit)

nicedit.jsを変更せずに動作するはずです

$("div.nicEdit-main").keyup(function () { });

jsfiddlehttp://jsfiddle.net/jGLRn/15/を見てください

于 2013-03-14T09:50:55.197 に答える
3

こちらの公式ドキュメントをお読みください。jQueryを使用せずに(サポートされている)イベントをnicEditインスタンスにバインドする方法を示します。

var commentNicEditor = new nicEditor().panelInstance('comment');
commentNicEditor.addEvent("blur", function () {
    // Sent when an editor instance loses focus    
});
commentNicEditor.addEvent("focus", function () {
    // Send when an editor gains focus (IE someone clicks inside it)    
});
commentNicEditor.addEvent("key", function () {
    // When the user presses a shortcut key (Such as control-b)    
});
commentNicEditor.addEvent("add", function () {
    // Fired when a new instance is added    
});
commentNicEditor.addEvent("panel", function () {
    // Fired when the toolbar is initialized for new instances (This is the preferred event if you want to add a function when NicEdit instances are created)    
});
于 2013-03-20T21:47:28.843 に答える
0

一日の調査の後、nicEdit.jsを変更せずにそれを行うことはできませんでした。しかし、私はほんの少しの変更で行うことができました。ここにあります(私はバージョン0.9r24を使用しています):

という名前の構成オプションを1つ追加しましcustomKeyDownFunctionた。デフォルトでは何もしません。

var nicEditorConfig = bkClass.extend({
    buttons : {
        'bold' : {name : __('Click to Bold'), command : 'Bold', tags : ['B','STRONG'], css : {'font-weight' : 'bold'}, key : 'b'},
        'italic' : {name : __('Click to Italic'), command : 'Italic', tags : ['EM','I'], css : {'font-style' : 'italic'}, key : 'i'},
        'underline' : {name : __('Click to Underline'), command : 'Underline', tags : ['U'], css : {'text-decoration' : 'underline'}, key : 'u'},
        'left' : {name : __('Left Align'), command : 'justifyleft', noActive : true},
        'center' : {name : __('Center Align'), command : 'justifycenter', noActive : true},
        'right' : {name : __('Right Align'), command : 'justifyright', noActive : true},
        'justify' : {name : __('Justify Align'), command : 'justifyfull', noActive : true},
        'ol' : {name : __('Insert Ordered List'), command : 'insertorderedlist', tags : ['OL']},
        'ul' :  {name : __('Insert Unordered List'), command : 'insertunorderedlist', tags : ['UL']},
        'subscript' : {name : __('Click to Subscript'), command : 'subscript', tags : ['SUB']},
        'superscript' : {name : __('Click to Superscript'), command : 'superscript', tags : ['SUP']},
        'strikethrough' : {name : __('Click to Strike Through'), command : 'strikeThrough', css : {'text-decoration' : 'line-through'}},
        'removeformat' : {name : __('Remove Formatting'), command : 'removeformat', noActive : true},
        'indent' : {name : __('Indent Text'), command : 'indent', noActive : true},
        'outdent' : {name : __('Remove Indent'), command : 'outdent', noActive : true},
        'hr' : {name : __('Horizontal Rule'), command : 'insertHorizontalRule', noActive : true}
    },
    iconsPath : '../nicEditorIcons.gif',
    buttonList : ['save','bold','italic','underline','left','center','right','justify','ol','ul','fontSize','fontFamily','fontFormat','indent','outdent','image','upload','link','unlink','forecolor','bgcolor'],
    iconList : {"bgcolor":1,"forecolor":2,"bold":3,"center":4,"hr":5,"indent":6,"italic":7,"justify":8,"left":9,"ol":10,"outdent":11,"removeformat":12,"right":13,"save":24,"strikethrough":15,"subscript":16,"superscript":17,"ul":18,"underline":19,"image":20,"link":21,"unlink":22,"close":23,"arrow":25},
    customKeyDownFunction : function() { }  
});

keyDown関数を変更しました。

keyDown : function(e,t) {
    this.ne.options.customKeyDownFunction();

    if(e.ctrlKey) {
        this.ne.fireEvent('key',this,e);
    }
}

nicEditorインスタンスを作成するときに、を定義しますcustomKeyDownFunction

var emailRtf = new nicEditor({  
        iconsPath : 'nicEdit/nicEditorIcons.gif', 
        buttonList : ['bold','italic','underline','fontSize','forecolor','ol','ul','link','unlink','removeformat'],
        maxHeight: 600,
        customKeyDownFunction: function() { alert('key down!'); }
    }).panelInstance('REPLY_MESSAGE');

カスタム関数が必要ない場合は、単に定義しないでくださいcustomKeyDownFunction

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

それが私にできる最善のことです。誰かがもっと良い方法を持っているなら、教えてください!

于 2013-03-14T00:13:08.627 に答える
0

または、次の方法で試すことができます。

$('body').on("keyup", ".nicEdit-main", function(){
  //Do Something...
}
于 2021-11-22T20:34:29.280 に答える