tinymce v4 jquery:如何抓住onkeyup?

时间:2013-06-05 11:48:10

标签: tinymce-4

我正在尝试在填写某些表单字段时启用提交按钮。我发现了一段可以运行的javascript代码,但是我遇到了textarea fiel的问题,这是由tinymce转换的...如何捕获它?

我的HTML:

<form id="form_id1">
<fieldset>
<legend>Personal</legend>
Name: <input type="text" size="30" /><br />
Email: <input type="text" size="30" /><br />
Date of birth: <input type="text" size="10" /><br />
Address : <textarea size="30"></textarea><br />

</fieldset>
<input type="submit" value="Submit" />
</form>

我的javascript:

$(document).ready(function()
{

    $('#form_id1 input:submit').attr("disabled", true);
    var textCounter = false;
    $('#form_id1 input:text, #form_id1 textarea').keyup(check_submit);

    function check_submit() {
        $('#form_id1 input:text, #form_id1 textarea').each(function()
          {
            if ($(this).val().length == 0) {
                textCounter = true;
                return false;
               }
            else {
                textCounter = false;
            }
         });

        $('#form_id1 input:submit').attr("disabled", textCounter);
    }
});

我的tinymce init:

tinymce.init({
                selector: "textarea",
                language: 'fr_FR',
                image_advtab: true,
                menubar:false,
                forced_root_block: false,
                plugins: ["link","code","media","image","textcolor", "emoticons"],
                toolbar: "bold italic forecolor backcolor alignleft aligncenter alignright alignjustify link unlink image media emoticons",
             });

由于

4 个答案:

答案 0 :(得分:19)

在tinymce init中添加:

setup: function(ed) {
    ed.on('keyup', function(e) {
        console.log('Editor contents was modified. Contents: ' + ed.getContent());
        check_submit();
    });
}

请记住,您可能需要找到您的编辑器实例而不是textarea才能获得实际值。如果你让textarea有id="textarea-tiny-mce"

tinymce.get('textarea-tiny-mce').getContent();

答案 1 :(得分:3)

    window.onload = function () {
        tinymce.get('content').on('keyup',function(e){
            console.log(this.getContent().replace(/(<[a-zA-Z\/][^<>]*>|\[([^\]]+)\])|(\s+)/ig,''));
        });
    }

答案 2 :(得分:0)

tinymce.init({    
        setup: function (editor) {
            editor.on('keyup', function (e) {
                console.log(e);
                //custom logic  
            });
        }
     });

答案 3 :(得分:0)

请在tinymce.init中进行以下更改

tinymce.init({
                selector: "textarea",
                setup: function(editor) {
                editor.on('keyup', function(e) {
                console.log('edited. Contents: ' + editor.getContent());
                check_submit();
                });
                }
                language: 'fr_FR',
                image_advtab: true,
                menubar:false,
                forced_root_block: false,
                plugins: ["link","code","media","image","textcolor", "emoticons"],
                toolbar: "bold italic forecolor backcolor alignleft aligncenter alignright alignjustify link unlink image media emoticons",
             });

有关更多详细信息,请参见以下参考资料。

https://www.tiny.cloud/docs/advanced/events/