TINYMCE set focus… just will not work

我只是一个虾纸丫 提交于 2019-12-13 12:29:13

问题


I've tried

tinyMCE.execInstanceCommand("content", "mceFocus");

I've tried

tinyMCE.execCommand('mceFocus', false, "content");

None of them seem to work :-(


回答1:


Well, I was stuck in the same problem. But I believe it depends where you execute the code. Here are various links that I've found so far:

http://tinymce.moxiecode.com/forum/viewtopic.php?id=8238

http://tinymce.moxiecode.com/forum/viewtopic.php?pid=91307#p91307


But I solved my issue the following, and it might not apply to yours:

this.focus();

this.tinymce.execCommand('mceFocus', false, 'yourTinyMCEtextAreaID_goes_here');

This code was applied inside the tiny_mce_src.js -> InsertHorizontalRule, just so you can have an idea of the scope.


Hope that helps.




回答2:


There is an even simpler way than the previous suggested code. When you initialize tinymce, there is an option to set the configuration parameters. Just make sure that you set the AUTOFOCUS option.

var editorOptions = {
    script_url: "/scripts/tinymce/tiny_mce.js",
    theme: "advanced",
    entities: "",
    theme_advanced_toolbar_location: "top",
    theme_advanced_toolbar_align: "left",
    theme_advanced_statusbar_location: "bottom",
    theme_advanced_resizing: true,
    content_css: "/styles/site.css",
    template_external_list_url: "lists/template_list.js",
    external_link_list_url: "lists/link_list.js",
    external_image_list_url: "lists/image_list.js",
    media_external_list_url: "lists/media_list.js",
    theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,bullist,numlist,|,undo,redo,|,link,unlink,anchor,image,help",
    theme_advanced_buttons2: "",
    theme_advanced_buttons3: "",
    theme_advanced_buttons4: "",
    width: "640",
    height: "220",
    auto_focus: "body2"
};


来源:https://stackoverflow.com/questions/5310005/tinymce-set-focus-just-will-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!