How do you set the focus of a TinyMCE textarea element?

后端 未结 13 1993
慢半拍i
慢半拍i 2020-12-29 20:33

I\'m using TinyMCE for a textarea on a page but it doesn\'t play nice in the tabbing order of the other elements.

I can use the following code to capture when I tab

相关标签:
13条回答
  • 2020-12-29 20:40

    This works for me (TinyMCE version 4.7.6):

    tinymce.activeEditor.fire("focus")
    
    0 讨论(0)
  • 2020-12-29 20:40

    I've got it to work with TinyMCE 4.x by using the following:

    tinymce.EditorManager.get('id_of_editor_instance').focus();

    0 讨论(0)
  • 2020-12-29 20:41

    Finally found an answer... use the command:

    tinymce.execCommand('mceFocus',false,'id_of_textarea');
    

    For my purposes, 'id_of_texterea' was "description", ie

    <textarea id="description" ... ></textarea>
    

    In the form element that preceded my textarea, I added the execCommand above to the element's "onblur" action.

    0 讨论(0)
  • 2020-12-29 20:42

    What actually works is setting an option in the configfile (or jquery file) This option enables you to auto focus an editor instance. The value of this option should be an editor instance id. The editor instance id is the id for the original textarea or <div> element that got replaced.

    Example of usage of the auto_focus option:

    tinyMCE.init({
        //...
        auto_focus : "elm1"
    });
    
    0 讨论(0)
  • 2020-12-29 20:42

    For Auto focus in tinymce the documentation first example says that - https://www.tinymce.com/docs/configure/integration-and-setup/#auto_focus

    tinymce.init({
          selector: '#textarea_id',
          auto_focus: '#textarea_id'
    });
    

    This works for me in TinyMCE Version 4.7.6

    0 讨论(0)
  • 2020-12-29 20:47

    This should pass focus to the TinyMCE textarea:

    $("#id_of_tinyMCE_area").focus();
    
    0 讨论(0)
提交回复
热议问题