1

假设用户选择(用他/她的鼠标)段落的第一行。稍后,他/她选择页面下方的另一行。有没有办法突出显示先前选择的文本(除了新选择的文本)?我怎样才能实现这一目标?

提前谢谢了。

4

2 回答 2

2

是的,您可以结合检查 mouseDown/mouseUp 事件和 document.selection/getSelection 来执行此操作。

一般的逻辑是这样的:

  1. 鼠标按下时,将 document.selection 的当前值保存到数组中(如果有选择)
  2. 在鼠标上,检查是否有任何选择。如果是这样,将其添加到同一个数组中
  3. 通过添加该数组中的每个范围来手动重做选择

你应该使用一些东西来处理跨浏览器的实现。看看这个人的片段

于 2012-02-10T05:33:11.057 回答
0

I do not believe so. The highlighting is not server-side/localhost controlled; It's a function usually built into the operating system that allows highlighting of text, or sometimes it's a function in the web browser.

Sorry I couldn't be more helpful or give you a solution that allows you to do this. Only other way I know is to use IFrames, because they act as oppositions from the primary page's highlighted elements/text.

于 2012-02-10T05:17:55.353 回答