可信的标签延续

Dra*_*cir 7 html javascript html5 contenteditable

介绍问题之前发生的事情:

在包含html标记的contenteditable中键入文本时,如果您位于标记的右侧,它将继续插入标记内.例如,如果我有这样的文字:

The <b>quick</b> fox jumped over the lazy dog.
Run Code Online (Sandbox Code Playgroud)

它就像这样渲染

快速 | 狐狸跳过懒狗.

我的光标位于管道位置,直接在单词quick之后.如果我进入棕色,我会得到

The <b>quick brown</b> fox jumped over the lazy dog. 
Run Code Online (Sandbox Code Playgroud)

快速褐色 | 狐狸跳过懒狗.

示例:http://jsfiddle.net/mBzvs/

我的问题是,如何删除其他标签(例如span)的标签延续功能?我想保留它作为<b>标签,但我不希望这发生在<span>标签上.

las*_*2d2 1

在有人找到更好的解决方案之前,我建议您设置contenteditable="false"标签<b>

The <b contenteditable="false">quick</b> fox jumped over the lazy dog
Run Code Online (Sandbox Code Playgroud)

自从:

  1. 您可能希望标签中的内容<b>不可编辑。如果没有,当他开始在该标签的最后一个字符旁边输入时,很难判断人们想要什么。
  2. It's easy to fulfill your second requirement:
    I'd like to keep it for the b tag but I don't want this to happen for the span tag.

Note: You need additional code for IE. See contenteditable=false inside contenteditable=true block is still editable in IE8