javascript 将图像插入 tinymce 编辑器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21854798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Insert an image into a tinymce editor
提问by Baz
I have a tinymce text box on my html page. Under this text box I have a table with my file system in which I can navigate to locate my images. I would like to be able to click on an image in this table and have it inserted in the timymce text box. How might I go about doing this?
我的 html 页面上有一个 tinymce 文本框。在此文本框下,我有一个包含我的文件系统的表格,我可以在其中导航以找到我的图像。我希望能够单击此表中的图像并将其插入到 timymce 文本框中。我该怎么做呢?
回答by user2314737
I've used the command
我已经使用了命令
tinyMCE.execCommand('mceInsertContent', false, '<img alt="Smiley face" height="42" width="42" src="' + sr + '"/>');
to insert the image in tinyMCE after extracting the URL from the image's src.
从图像的src.
Note that you need to pass the CSS style of the image to tinyMCE in the command.
请注意,您需要在命令中将图像的 CSS 样式传递给 tinyMCE。
EDIT: for Tiny MCE 4.x, the insert image code can be simplified to: tinymce.activeEditor.insertContent('<img alt="Smiley face" height="42" width="42" src="' + sr + '"/>');
编辑:对于 Tiny MCE 4.x,插入图像代码可以简化为: tinymce.activeEditor.insertContent('<img alt="Smiley face" height="42" width="42" src="' + sr + '"/>');
Here's the demo.
这是演示。

