3

我在一页上有多个 TinyMCE 编辑器,我需要在特定的一个中插入 HTML,目前当我插入 HTML 时,它会将其插入最后一个:

我的初始化代码:

<script type="text/javascript">
$(document).ready(function() {

    // enable tinyMCE on shortDescription
    tinymce.init({
        mode : "exact",
        elements :"shortDescriptionHtml",
        plugins: [
            "advlist autolink lists link image charmap print preview anchor",
            "searchreplace visualblocks code fullscreen",
            "insertdatetime media table contextmenu paste"
        ],
        toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
        relative_urls : false,
        remove_script_host : false
    });

    // enable tinyMCE on fullDescription
    tinymce.init({
        mode : "exact",
        elements :"fullDescriptionHtml",
        plugins: [
            "advlist autolink lists link image charmap print preview anchor",
            "searchreplace visualblocks code fullscreen",
            "insertdatetime media table contextmenu paste"
        ],
        toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
        relative_urls : false,
        remove_script_host : false
    });

    // enable tinyMCE on Terms And Conditions
    tinymce.init({
        mode : "exact",
        elements :"termsAndConditionsHtml",
        plugins: [
            "advlist autolink lists link image charmap print preview anchor",
            "searchreplace visualblocks code fullscreen",
            "insertdatetime media table contextmenu paste"
        ],
        toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
        relative_urls : false,
        remove_script_host : false      
    });

});
</script>

现在当我尝试做

tinyMCE.execCommand('mceInsertContent',false,'<img src="'+imgsrc+'" />');

它在最后一个 TinyMCE 编辑器中插入图像,这是条款和条件之一,我如何将该图像插入第一个或第二个 TinyMCE 编辑器?

4

2 回答 2

2

您应该获得某个编辑器实例。我猜,是这样的:tinymce.get($(el).attr('id'));

看看这个:http: //jsfiddle.net/svCp2/。这里的行是:

tinymce.get('c3').setContent('sdf');
于 2013-09-11T06:25:21.313 回答
0
tinymce.get("editorID").execCommand(
    'mceInsertContent',
    false,
    '<img src="'+imgsrc+'" />'
);

其中“editorID”是您的编辑器 ID 选择器

<div id="editorID">...</div>
于 2014-12-25T13:40:45.600 回答