将光标/插入符号放在contentEditable onFocus中的特定位置

时间:2014-08-06 18:55:17

标签: javascript jquery html html5 contenteditable

character事件发生时,我试图将光标保持在contentEditable div中的特定.focus()

这是我的内容可编辑div(.textA),内容如下:

<div class='textA' contentEditable='true'>
Hello There to all <div class='xyz' contentEditable='true'>SO</div> Users.<br>
Can you all Please <div class='abc'>Solve</div> This for me?<br>
<br>
<br>
<div class='xyz'>VT</div>
</div>

然后我试图以这样的方式在function placeCaretAt(position)中开发javascript

它将光标放在position事件上该div的.text()的{​​{1}}个字符处。

即,例如:当它被称为

focus

那么它应该将光标放在$('.textA').focus(function(){ placeCaretAt(20); }); &amp;之间。 SO用户SO,如<div class='xyz' contentEditable='true'>S|O</div>

text获取tagscontentEditable我使用Jquery的.text()

专家可以帮助我吗?欢迎任何帮助/建议/建议:)。提前谢谢。

我已经看过了:

How to set caret(cursor) position in contenteditable element (div)?

jquery Setting cursor position in contenteditable div

Set cursor position on contentEditable <div>

但它们对我毫无用处。坏运气和一天:(。请帮助我专家。

0 个答案:

没有答案
相关问题