html - 在 Firefox 上按下退格键时,可编辑 div 中的空 HTML 标记消失
问题描述
我正在使用 Firefox,我有这个 HTML 代码:
<div contenteditable="true">
This is an empty tag : <b></b> and this is this is <b>not</b>
</div>
当我尝试通过按“SUPPR”或“BACKSPACE”键删除字符时,它会<b></b>
无缘无故地删除。
它适用于 Chrome。
检查这里:https ://jsfiddle.net/t5jgb04y/ 然后尝试删除一个字符。
解决方案
我认为在这种情况下 Firefox 比 Chrome 更智能,因为你不能<b></b>
在<div contenteditable>
. 尝试在<b>
使用键盘箭头或鼠标导航时在标签中插入内容 -你不能。所以基本上 Firefox 只是在任何更改时删除这种标签,因为它们根本不可用。
现在更改<b></b>
为<b> </b>
甚至<b> </b>
在这些<b>
标签之间留一个空白空间 - Firefox 不会<b>
在更改时自动远程处理标签,您现在可以导航和编辑其内容。
这是您的示例:
b {
background-color: lightblue;
padding: 10px;
}
<div contenteditable="true">
This is an empty tag : <b></b> and this is <b>not</b>
</div>
这是我的示例,标签之间有空格字符<b> </b>
:
b {
background-color: lightblue;
padding: 10px;
}
<div contenteditable="true">
This is an empty tag : <b> </b> and this is this is <b>not</b>
</div>
另一个示例只是在标签之间留有空白<b> </b>
- 在这种情况下,您只能<b></b>
使用键盘箭头在 之间导航:
b {
background-color: lightblue;
padding: 10px;
}
<div contenteditable="true">
This is an empty tag : <b> </b> and this is this is <b>not</b>
</div>
推荐阅读
- reactjs - 如何在 gatsby 中使用 react-icons 但不影响性能?
- redux - 具有所需负载的 createAction
- r - 如何去除死把手
- python - 将 .bin 文件中的 3D 点云数据转换为 .pcd 文件
- php - 如何将 ID 元素添加到 Add To Cart?
- c# - LinQ to XML,选择具有 2 级搜索条件的节点
- javascript - addeventlistener 直接在promise 下使用时不起作用,但在promise 下使用settimeout 可以正常工作
- python - Bing 壁纸捕手与 python
- pdf - fig 文件包含在函数 include_graphics() 中,当 rmd 转为 pdf/tex 时可能会丢失文件扩展名
- linux - 如何在我的配置命令中定义 _POSIX_VERSION?