JS获取选中文本


<!DOCTYPE html>html

<html>测试

<head>this

    <meta charset="UTF-8">htm

    <title></title>ip

</head>get

<body>it

<div onmouseup="funGetSelectTxt()">this is test 这是测试</div>io

<textarea onmouseup="funGetSelectTxt()">function


</textarea>test


</body>

<script>

    //选中文字

    var funGetSelectTxt = function() {

        var txt = '';

        if(document.selection) {

            txt = document.selection.createRange().text;

            alert(txt+'---------');

        } else {

            txt = document.getSelection();

            alert(txt+'==========');

        }

        return txt.toString();

    };

</script>


</html>

相关文章
相关标签/搜索