【发布时间】:2016-06-15 15:47:58
【问题描述】:
我想为用户在我的网页上选择的文本应用一种样式,例如黄色背景。不幸的是,所选文本可能会跨越节点边界(例如,它可能从一个 div 的中间开始,在另一个 div 的中间结束)。
将跨度(或多个跨度)环绕所有选定文本的最佳方式是什么?
设置
<div>This sentence is not selected. THIS SENTENCE </div>
<div>IS SELECTED. This sentence is not selected.</div>
想要的结果
<div>This sentence is not selected. <span>THIS SENTENCE</span> </div>
<div> <span>IS SELECTED.</span> This sentence is not selected.</div>
【问题讨论】:
标签: javascript jquery selection word-wrap