使用 Window.getSelection() 和 Selection.toString() 获取当前选定的文本。 getSelection() 返回一个 Selection 对象,表示用户选择的文本范围或光标的当前位置。 const getSelectedText = window.getSelection().toString() 查看效果
使用 Window.getSelection() 和 Selection.toString() 获取当前选定的文本。 getSelection() 返回一个 Selection 对象,表示用户选择的文本范围或光标的当前位置。 const getSelectedText = window.getSelection().toString() 查看效果