textarea,tinyMCE并在textarea中插入图像 [英] textarea, tinyMCE and insert an image in textarea

查看:124
本文介绍了textarea,tinyMCE并在textarea中插入图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用jquery在textarea中插入图像. (我知道img标签无法插入textarea中).我正在使用tinymce

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>

在config.js中,我有:

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.

推荐答案

您需要调用 mceInsertContent命令,如下所示:

You need to call the mceInsertContent command, like this:

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

如果您切换到jQuery插件版本,它将看起来像这样:

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

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

这篇关于textarea,tinyMCE并在textarea中插入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆