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>

相關文章
相關標籤/搜索