html - ContentEditable 元素一旦为空就会松开光标

标签 html google-chrome

当我清除一个contenteditable div的内容时,光标立即丢失,我无法通过点击将其恢复。所以如果我清除一次就无法添加任何内容。

在这里检查一下:

<div contenteditable>
  asdasd
  <div contenteditable="false">x</div>
</div>

删除第一行的“asdasd”。一旦你删除了最后一个可删除的字符,光标就消失了,我再也找不回来了。

我刚在 firefox 中试过,效果很好。所以这是 chrome 特有的。

最佳答案

这应该可以解决您的问题。即使该区域为空,您也可以单击该区域并取回光标。查看以下链接:

Restore cursor position after changing contenteditable

关于html - ContentEditable 元素一旦为空就会松开光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38492935/

相关文章:

css - 在谷歌浏览器中打印日历时,边框不显示

jquery - Angular mouseenter 在 Chrome 中不起作用

python - 未下载 CSS 文件 - Flask

html - 更改 radio 颜色 Material 设计

php - Bootstrap 表单对齐

html - 响应式侧边栏 wordpress 主题

html - 下拉对齐

html - 如何使用图像创建 Angular 导航

javascript - 内容脚本、后台脚本和弹出脚本之间的通信

google-chrome - 强制 Chrome 跟随 URL 而不是搜索