ckedit 在源码模式下插入文本
2015-06-01 16:48 风来之东林 阅读(330) 评论(0) 编辑 收藏 举报ckedit的源码模式下是禁用insertText方法的 ,下面是解决方案
if(CKEDITOR.instances[Itemname].mode=='wysiwyg'){ CKEDITOR.instances[Itemname].insertText(TextToInsert); } else{ var input = document.getElementsByClassName('cke_source cke_enable_context_menu')[0]; input.focus(); if(typeof input.selectionStart != 'undefined') { /* Einfügen des Formatierungscodes */ var start = input.selectionStart; var end = input.selectionEnd; input.value = input.value.substr(0, start) + TextToInsert + input.value.substr(end); /* Anpassen der Cursorposition */ var pos; pos = start+TextToInsert.length; input.selectionStart = pos; input.selectionEnd = pos; } }