1

我正在使用 ckeditor 在站点上添加帖子:

<textarea class="ckeditor" cols="80" id="editor1" name="editor1" rows="10"></textarea>

当我通过 jquery 单击按钮时,我想将一些文本或图像附加到它的文本区域。

我试过这个但没有奏效:

<script>
$(document).ready(function(){
$('.button').click(function(){
  img = "<img src='http://localhost/sdn/files/uploads/1368647314.png'/>'";
  $(".cke_editable").append(img); // also I tried:  $("#editor1").append(img);
});
});
</script>

谢谢你。

4

3 回答 3

2

使用CKEditor API

<script>
$(document).ready(function(){
$('.button').click(function(){
  img = "<img src='http://localhost/sdn/files/uploads/1368647314.png'/>'";
  CKEDITOR.instances.editor1.insertHtml(img);
});
});
</script>
于 2013-05-16T06:46:26.033 回答
2

用这个 :

<script>
$(document).ready(function(){
$('.button').click(function(){
  img = "<img src='http://localhost/sdn/files/uploads/1368647314.png'/>'";
  CKEDITOR.instances.editor1.setData(img);
});
});
</script>
于 2013-05-16T11:54:49.323 回答
1
var img=$("<img src='http://localhost/sdn/files/uploads/1368647314.png'/>");

看起来你在那里有一个额外的报价,我想你可能需要把它变成一个 jquery 对象。确保使用var关键字将变量保持在本地。

于 2013-05-15T20:31:30.680 回答