开发者

textarea, tinyMCE and insert an image in textarea

开发者 https://www.devze.com 2023-01-20 10:16 出处:网络
I want to insert an image in textarea with jquery. (I know that img tag could not to inserted in textarea). Im using 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开发者_如何学JAVA="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.


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+'"/>');
0

精彩评论

暂无评论...
验证码 换一张
取 消