2010-10-12 94 views
2

我想用jquery在textarea中插入圖像。 (我知道img標籤不能插入到textarea中)。即時通訊使用TinyMCE的textarea,tinyMCE並在textarea中插入圖像

<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我:

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

    });}); 

點擊時,圖像不可能在textarea的插入。如何做到這一點? 在此先感謝。

回答

5

你需要調用mceInsertContent command,就像這樣:

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

如果切換到jQuery插件版本,它會是這樣的:

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

非常感謝。它的工作完美的ff,但不是在ie。 – TheNone 2010-10-12 21:10:27

+0

@phpExe - 有一個示例頁面?我使用的jQuery版本沒有問題,不知道如果普通版本有任何IE怪癖 – 2010-10-12 21:11:23

+0

Im sorry,這是關於activeX禁用js。在ie中也完美工作。謝謝。 – TheNone 2010-10-12 21:18:18