TINYMCE设定焦点...只是不起作用

时间:2011-03-15 09:51:53

标签: javascript focus tinymce set

我试过

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

我试过

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

它们似乎都不起作用: - (

2 个答案:

答案 0 :(得分:6)

好吧,我遇到了同样的问题。但我相信这取决于你执行代码的位置。以下是我到目前为止发现的各种链接:

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

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


但我解决了以下问题,可能不适用于你的问题:

this.focus();

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

此代码已应用于tiny_mce_src.js - > InsertHorizo​​ntalRule,这样你就可以了解范围。

希望有所帮助。

答案 1 :(得分:4)

有一种比以前建议的代码更简单的方法。初始化tinymce时,可以选择设置配置参数。只需确保设置AUTOFOCUS选项。

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"
};