javascript - contenteditable div 中突出显示的文本 : Get the start and the end of the highlighted text

标签 javascript jquery html css

<div contenteditable="true">This text is <b>Bold</b> not <i>Italic</i> right?</div>

例如,如果

text is Bold not

由用户选择,我如何知道选择(突出显示)的确切位置(偏移)。我读过几篇有关此的文章,但找不到一篇对此进行解释的文章。 谢谢

最佳答案

最好的解决方案可能是用一个元素包围所选文本,然后获取该元素的位置,请参阅:How can I position an element next to user text selection?

关于javascript - contenteditable div 中突出显示的文本 : Get the start and the end of the highlighted text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32476650/

相关文章:

javascript - 如何使用 DOM 更改表格内单行的背景颜色

jquery - 如何使用jquery在gridview中获取选定的(单选按钮)行值(标签)

Javascript 生成的日历在 mozilla firefox 和 chrome 中显示不同

javascript - 在 html 中输入日期和时间(来自用户)并在 Javascript 中接收的最佳方法是什么?

jquery - 如何从markerclustererplus获取点击事件

html - 高阶 li 的 CSS 选择器

javascript - 许多图像加载 HTML/Javascript 性能

javascript - 如何使用 javascript 读取 sharePoint 列表项值(当前项)

javascript - 覆盖自动生成的CSS

jQuery mouseoverIntent 不起作用,但悬停可以