【问题标题】:tinymce setcontent makes existing disappertinymce setcontent 使现有消失
【发布时间】:2015-12-04 07:20:04
【问题描述】:

我正在尝试使用

在 tinymce 编辑器中添加一些额外的隐藏内容

tinyMCE.get('addCustom_id').setContent(data);

一旦对事件执行上述行,setContent 之前的现有内容就会消失。我想保留现有内容并添加额外内容。请帮助。

下面是tinymce的初始化代码

tinymce.init({
    mode : "specific_textareas",
    selector : '#customArea textarea',
    plugins: [
            "advlist autolink autosave link image lists charmap print preview hr anchor pagebreak spellchecker",
            "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
            "table contextmenu directionality emoticons template textcolor paste fullpage textcolor"
    ],

    toolbar1: "newdocument fullpage | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | styleselect  fontselect fontsizeselect",
    toolbar2: "searchreplace | bullist numlist | outdent indent blockquote | undo redo | link unlink anchor image media code | inserttime preview | forecolor backcolor",
    toolbar3: "table | hr removeformat | subscript superscript | charmap emoticons | print fullscreen | ltr rtl | spellchecker | visualchars visualblocks nonbreaking template pagebreak restoredraft",
    image_advtab: true,     
    importcss_append: true,
    //visual_table_class: "product_table_1",
    //visual_table_class: "product_table_2",
     content_css:  "/bvmc/filegallery/static/tempcss/jquery-ui-small.css,/bvmc/filegallery/static/tempcss/style_small.css,/bvmc/filegallery/static/tempcss/style_small_2.css,/bvmc/filegallery/static/tempcss/style_small_3.css,/bvmc/filegallery/static/tempcss/tinyMCE.css,/bvmc/filegallery/static/tempcss/table_style.css",
    valid_children : "+p[h1|h2|h3|h4|h5|h6]",
    menubar: false,
    toolbar_items_size: 'small',
    style_formats: [    
{title: "Headers", items: [
    {title: "Header 1", inline: "h1"},
    {title: "Header 2", inline: "h2"},
    {title: "Header 3", inline: "h3"},
    {title: "Header 4", inline: "h4"},
    {title: "Header 5", inline: "h5"},
    {title: "Header 6", inline: "h6"}
]},
{title: "Inline", items: [
    {title: "Bold", icon: "bold", format: "bold"},
    {title: "Italic", icon: "italic", format: "italic"},
    {title: "Underline", icon: "underline", format: "underline"},
    {title: "Strikethrough", icon: "strikethrough", format: "strikethrough"},
    {title: "Superscript", icon: "superscript", format: "superscript"},
    {title: "Subscript", icon: "subscript", format: "subscript"},
    {title: "Code", icon: "code", format: "code"}
]},
{title: "Blocks", items: [
    {title: "Paragraph", format: "p"},
    {title: "Blockquote", format: "blockquote"},
    {title: "Div", format: "div"},
    {title: "Pre", format: "pre"}
]},
{title: "Alignment", items: [
    {title: "Left", icon: "alignleft", format: "alignleft"},
    {title: "Center", icon: "aligncenter", format: "aligncenter"},
    {title: "Right", icon: "alignright", format: "alignright"},
    {title: "Justify", icon: "alignjustify", format: "alignjustify"}
]}
    ]

});

【问题讨论】:

    标签: javascript html tinymce


    【解决方案1】:

    setContent 重置整个编辑器内容。

    你可以使用

    tinyMCE.get('addCustom_id').execCommand('insertHTML', false, data);
    

    在编辑器的当前插入符号位置添加内容。 实际选择将被替换。

    【讨论】:

    • 很高兴能够提供帮助
    • 但我没有使用tinyMCE.get('addCustom_id') 取回添加的内容,即使它存在于tinymce 的视图源中??
    • 用 tinyMCE.get('addCustom_id') 你得到他的编辑器实例。要获取编辑器内容,请使用 tinyMCE.get('addCustom_id').getContent();
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多