简体   繁体   English

在contentEditable模式下移动光标

[英]move cursor in contentEditable mode

I have a problem with contentEditable, at least in chrome divs and spans are added as the user edits the text content in the DIVs. 我在使用contentEditable时遇到问题,至少在chrome div中,随着用户在DIV中编辑文本内容,添加了跨度。

Once the DIV is opened for edit, I can move my cursor around by single-clicking (left mousebutton) but if the text I want to move the cursor to resides within one of the sub-divs or sub-spans added by chrome, the cursor is not moved but instead taken out of the div all together, and I have to activate the contenteditable again. 打开DIV进行编辑后,我可以通过单击(鼠标左键)来移动光标,但是如果要移动光标的文本位于由chrome添加的细分或子跨度之一内,光标不会移动,而是一起移出div,我必须再次激活contenteditable。

Is there a way around this or can I do nothing about it? 有没有解决的办法,还是对此我什么也不能做?

Here is my solution: 这是我的解决方案:

jquery remove <span> tags while preserving their contents (and replace <divs> and <p>:s with <br>) jQuery删除<span>标记,同时保留其内容(并用<br>替换<divs>和<p>:s)

in short, pull out all text from divs and p tags, substitute their opening tags with a br, and for those span tags that keep appearing upon backspace (in chrome), I just unwrap them. 简而言之,从div和p标签中拉出所有文本,用br替换其开头标签,对于那些不断出现在退格键(在chrome中)的span标签,我只是将它们拆开。 That gets rid of the style automatically. 这会自动摆脱样式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM