Ram*_*esh 2 selection ckeditor
我有一个小代码来选择CKEditor中的文本.为此我在javascript中使用以下代码.
var docx = editor.document;
var elementx = docx.getById(id);
editor.getSelection().selectElement(elementx);
editor.getSelection().scrollIntoView(true);
Run Code Online (Sandbox Code Playgroud)
它在Mozilla Firefox中工作正常.但是在IE9中它会抛出一个错误,因为selectElement不是一个对象.所以我检查了代码,发现getSelection()具有空值.请帮我解决一下.我在各个网站上尝试了一些答案,即使在CKEditor四分钟也没有帮助我.
这是正确的解决方案:
var editor = CKEDITOR.instances.editor1;
editor.focus(); // Without this selection will be null on IE.
var element = editor.document.getBody().getLast(),
selection = editor.getSelection();
selection.selectElement(element); // You have to reuse selection.
selection.scrollIntoView();
Run Code Online (Sandbox Code Playgroud)
我在http://ckeditor.com/demo上的Firefox,Chrome和IE8上通过控制台对它进行了测试,结果很有效.
归档时间: |
|
查看次数: |
2521 次 |
最近记录: |