← 全部文章

用JavaScript获取选中的文字

function getSelectText() {
    return document.selection && document.selection.createRange().text || window.getSelection && window.getSelection() || document.getSelection && document.getSelection() || '';
}

支持 IE6、Firefox 和 Chrome

原文:

用JavaScript获取选中的文字

参考:

获取鼠标选择的文本内容之JavaScript代码

参考:

Use JavaScript and jQuery to Get User Selected Text, and then Do Something (Useful?) With It