我试图从光标位置提取所有文本。下面是代码,我使用:函数从CKEditor中的光标位置获取文本行为奇怪
originalText = editor.getData();
var startTag = "<span id=\x22Start\x22> </span>";
var stopTag = "<span id=\x22Stop\x22> </span>";
var startElement = CKEDITOR.dom.element.createFromHtml(startTag, editor.document);
editor.insertElement(startElement);
sText = editor.getData();
sText1 = sText + stopTag;
editor.setData(sText1);
// up to here, I've incapsulated the required text with span tags
// Using the replace function, I remove end tag of the Start span as well as removing the start tag of the Stop span!
sText1 = editor.getData();
sText2 = sText1.replace("<span id=\"Start\"> </span>", "<span id=\"Start\">");
sText2 = sText2.replace("<span id=\"Stop\"> </span>", "</span>");
// I set the data (HTML) back to the editor
editor.setData(sText2);
//alert(sText2);
// I use the innerHTML to get the text
el = editor.document.$.getElementById("Start");
return el.innerHTML;
问题: 的el.innerHTML工作正常,但只有当警报()是取消注释!我知道setData是异步的,并通过使用setData()上的回调将解决问题,但不幸的是它不适用于我:(
你想做什么?意思是什么你的recuirements?我认为这里的答案是完全重构你做事的方式。 – Nenotlep