jQuery Cleditor get textarea value on keyup

前端 未结 3 2000
被撕碎了的回忆
被撕碎了的回忆 2021-02-08 10:19

I\'m using Cleditor http://premiumsoftware.net/cleditor/docs/GettingStarted.html. I want to get the value on keyup and insert the text into another div. cleditor comes with chan

3条回答
  •  我在风中等你
    2021-02-08 10:54

    I was able to achieve this by slightly modifying the source code of the editor - in refresh method (line 801) I modified the blur event handler of iframe doc.

    Previous

    // Update the textarea when the iframe loses focus
        ($.browser.mozilla ? $doc : $(contentWindow)).blur(function() {
          updateTextArea(editor, true);
        });
    

    Modified to

    // Update the textarea when the iframe loses focus or keyup happens
            ($.browser.mozilla ? $doc : $(contentWindow)).bind('blur keyup', function (e) {
                updateTextArea(editor, true);
    
                if (options.keyup && e.type === 'keyup')
                    options.keyup(editor.$area.val());
            });
    

    and in the options that are passed at the time of initialisation, you can define

    $("#element").cleditor({
    keyup : function (text) {
     alert(text);
     // do something
    }
    });
    

    Hope this helps anyone.

    Regards

提交回复
热议问题