textarea, tinyMCE and insert an image in textarea

别说谁变了你拦得住时间么 提交于 2019-12-10 11:27:51

问题


I want to insert an image in textarea with jquery. (I know that img tag could not to inserted in textarea). Im using tinymce

 <img src="image.jpg" class="po"/>
 <form>
 <input type="text" name="yassi" class="infobox"/>
 <br />
 <textarea class="me"></textarea>
 <input type="submit"   value="click"  class="submit"/>
 </form>

jquery:

<script type="text/javascript">
tinyMCE.init({
mode : "textareas",
theme : "simple"
});
</script>
<script type="text/javascript" scr="config.js">
</script>

and in config.js I have:

 $(document).ready(function(){
    var sr = $('.po').attr('src');
    $('.po').click(function(){
        $('.mceContentBody').append('<img src="'+sr+'"/>');

    });});

When clicking, image couldnt insert in textarea. How can do this? Thanks in advance.


回答1:


You need to call the mceInsertContent command, like this:

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

If you switch to the jQuery plugin version, it'd look like this:

$('.mceContentBody').tinymce().execCommand('mceInsertContent',false,'<img src="'+sr+'"/>');


来源:https://stackoverflow.com/questions/3918773/textarea-tinymce-and-insert-an-image-in-textarea

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