<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div οnmοuseup="funGetSelectTxt()">this is test 这是测试</div>
<textarea οnmοuseup="funGetSelectTxt()">
</textarea>
</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>