兰吉& ContentEditable-设置插入符号 [英] Rangy & ContentEditable - Set the Caret

查看:97
本文介绍了兰吉& ContentEditable-设置插入符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用最新版本的"rangey" jQuery插件(1.2 beta),以可修改内容的DIV中的插入符号设置特定的偏移量.

I'm trying out the latest version of the "rangy" jQuery plugin (1.2 beta) to set the caret in a contenteditable DIV with a specific offset.

但是,它在Firefox中出现一个奇怪的错误: 安全错误"代码:"1000

However, it responds with a weird error in Firefox: Security error" code: "1000

这是令人讨厌的代码:

var el = $("#editablediv"), index = 11;
var range = rangy.createRange();
range.setStart(el, index);
var sel = rangy.getSelection();
sel.setSingleRange(range);

调用setStart函数时,代码失败.

The code fails when calling the setStart function.

任何人都可以举一个合理使用rangy的例子吗?

Could anyone give an example of the proper usage of rangy please?

推荐答案

我发现了这个问题,我应该通过正确的节点,即文本节点:

I found the issue, I was supposed to pass through the correct node which is the text node:

var el = $("#editablediv"), index = 11;
var range = rangy.createRange();
range.setStart(el[0].childNodes[0], index);
range.collapse(true);
var sel = rangy.getSelection();
sel.setSingleRange(range);

这篇关于兰吉& ContentEditable-设置插入符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆