如何设置一个按钮,点击按钮时,在CKEditor编辑器中输入一段设定好的内容或代码,下面我们给出详细操作:
第一步:
设置编辑器的id=“editor”,比如ckeditor嵌套在textarea中,那么设置textarea的id属性为editor
同时设置点击事件:οnclick=“tjdmp()”
第二步:
编写javascript脚本:
有两种输入指定内容的方法:
第一种:
使用setData方法,这种会全部替换编辑器的所有内容,一般用于设置默认输入内容的场景。
<script language="javascript">
function tjdmp(){
CKEDITOR.instances.editor.setData("指定内容");//editor为id属性
}
</script>
第二种:
使用insertHtml方法,这种会在编辑器的的指定位置出添加指定内容,一般用于添加代码片功能等,相当于点击一个按钮,编辑器就会在鼠标位置添加一段设定好的内容或代码。
<script language="javascript">
function tjdmp(){
CKEDITOR.instances.editor.insertHtml("指定内容");//editor为id属性
}
</script>
原文链接:https://www.js1331.com/jiaocheng?id=279000