Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: getSelection() 在 IE 中不起作用
我试图获取选定的内容,我发现了这个:
window.getSelection().toString();
它适用于大多数浏览器,除了显而易见的 IE。
那么该怎么办?
完整的语法是:
document.selection.createRange().text;
只有 IE9 及以上版本支持window.getSelection(). 您可以document.selection在早期版本中使用。
window.getSelection()
document.selection