将插入符号设置为在焦点CKEditor之后结束
Set caret to end after focus CKEditor
可能重复:
CKEditor-将光标位置设置为文本的末尾
我有一个内容丰富的<div>
。单击该div后,将加载CKEditor来编辑该div。
现在,我想在用编辑器替换插入符号/光标后,将其设置到内容的末尾。
我目前的代码是这样的:
var editor = CKEDITOR.replace('content', {
// Settings
// Event listeners
on: {
instanceReady: function(evt) {
var editor = evt.editor;
// give focus (displays caret at the beginning of the content, not the end)
editor.focus();
}
}
});
经过一番修改,我可以使用以下代码:
$(document).ready(function() {
CKEDITOR.on('instanceReady', function(ev) {
ev.editor.focus();
var s = ev.editor.getSelection(); // getting selection
var selected_ranges = s.getRanges(); // getting ranges
var node = selected_ranges[0].startContainer; // selecting the starting node
var parents = node.getParents(true);
node = parents[parents.length - 2].getFirst();
while (true) {
var x = node.getNext();
if (x == null) {
break;
}
node = x;
}
s.selectElement(node);
selected_ranges = s.getRanges();
selected_ranges[0].collapse(false); // false collapses the range to the end of the selected node, true before the node.
s.selectRanges(selected_ranges); // putting the current selection there
}
});
想法是:
- 获取根节点(而不是主体(
- 前进到下一个节点,直到没有更多节点可前进
- 选择最后一个节点
- 折叠它
- 设置范围
相关文章:
- CKEditor Widget-阻止编辑可编辑元素本身
- keyup事件处理程序更改焦点不适用于快速键入
- 单击时将焦点更改为元素
- Ckeditor-plugin:插入虚假元素add不情愿<p>标签前后
- 后焦点更改为IE 11中的地址栏,而不是转移到表单中的下一个控件
- CKEditor-我在editor.css中的风格是't
- CKeditor:更改对话框中的默认选择选项
- 删除CKEditor工具栏按钮,但不删除功能
- 在IE9中的输入字段中输入焦点最近按钮
- Javascript游戏输入失去焦点
- ExtJS网格单元格编辑器,防止焦点松动问题
- CKEditor v4:自制插件中对话框的动态标题
- CKEditor光标在Chrome中的焦点上不闪烁
- CKEditor在焦点/单击时更改配置设置
- 工具栏折叠命令使 CKEDITOR 成为焦点
- 在 CkEditor 中输入焦点
- 将插入符号设置为在焦点CKEditor之后结束
- ckeditor:如何在焦点上选择编辑器内的所有文本
- CKEditor:通过JS从内联编辑器中逃脱编辑器焦点(不需要鼠标点击)
- CKEditor在焦点上删除默认值