将插入符号放在ContentEditable的插入标记之外 [英] Placing caret outside of inserted tag in ContentEditable

查看:112
本文介绍了将插入符号放在ContentEditable的插入标记之外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 document.execCommand insertHTML 方法将span标记插入到contentEditable div中。

I am inserting a span tag into a contentEditable div using the document.execCommand insertHTML method.

插入后,我希望在输入的末尾设置插入符号,以便在最后插入的span标签之外进一步输入。至少在Chrome中,默认行为是在标签本身内部放置更多输入。

After the insertion, i want the caret to be set at the end of the input, so that any further input is outside of the last inserted span tag. The default behavior, at least in Chrome is to place further input within the tag itself.

推荐答案

直到我尝试了这个。


I was stuck on this as well until I tried this. Place a   at the end of your insert as in

document.execCommand('insertHTML', false, '<span>&nbsp;</span>&nbsp;');

只要在HTML末尾放置一个空格就行不通,因为我发现它总是被修剪。

Just putting a space at the end of your HTML will not work as I have found it is always trimmed.

这篇关于将插入符号放在ContentEditable的插入标记之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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