简体   繁体   English

内容可编辑,可防止在某些元素后插入符号

[英]Contenteditable prevent caret placement after a certain element

I have a certain contenteditable div, inside this div I have some tags that are immediately followed by tags so it will be like this 我有一个特定的contenteditable div,在这个div中,我有一些标签,标签后面紧跟着标签,因此它将像这样

<span class="formatting-holder"></span>
|<b></b>|
<span class="formatting-holder-close"></span>

The | | character denote the places where I need to prevent the caret from being positioned, the caret should only be placed inside the <b></b> but not between the <span> and the <b> . 字符表示我需要防止插入符号放置的位置,插入符号应仅放置在<b></b>而不能放置在<span><b>

Is there a way to do this? 有没有办法做到这一点?

Use CSS 使用CSS

One of the best ways to accomplish what you're after is by using CSS which displays your "|" 达成目标的最好方法之一是使用显示“ |”的CSS characters and also prevents caret from being positioned on them 字符,还可以防止将插入符号放置在这些字符上

<span class="formatting-holder"></span>
<b></b>
<span class="formatting-holder-close"></span>

and in your CSS define this 然后在您的CSS中定义

.formatting-holder:before,
.formatting-holder:after {
    content: "|";
}

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

相关问题 contentEditable javascript插入div中的插入符号 - contentEditable javascript caret placement in div 在contentEditable div中的inserted元素后面设置插入位置 - Set caret position right after the inserted element in a contentEditable div 在contenteditable div中的插入位置之前和之后获取节点/元素 - Get node/element before and after caret position in contenteditable div 在contenteditable div中创建新元素后设置插入符号 - Set caret after creating new element in contenteditable div 更改 contenteditable 元素的 innerHTML 后,将插入符号放回原来的位置 - Place caret back where it was after changing innerHTML of a contenteditable element 将占位符插入符号置于contentEditable元素中 - Centering the placeholder caret in contentEditable element 如何在原始文本中间粘贴HTML单词后,防止插入符号在contenteditable div中跳到整个文本的末尾? - How to prevent the caret jumping to the end of the whole text in contenteditable div after pasting the HTML words in the middle of the original text? javascript:将插入符号移动到元素的结尾(div与contenteditable) - javascript: move caret to end of element (div with contenteditable) Contenteditable - 从插入符号提取文本到元素结尾 - Contenteditable - extract text from caret to end of element contentEditable在特定元素内设置插入符号 - contentEditable set caret inside a particular element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM