<script>
function getSelectionText() {
var s = "";
if(window.getSelection) {
s=window.getSelection().toString();
//return window.getSelection().toString();
} else if(document.selection && document.selection.createRange) {
s=document.selection.createRange().text;
//return document.selection.createRange().text;
}
document.getElementById("tt").value=s;
//return '';
}
</script>
</HEAD>
<BODY onSelect="getSelectionText()">
本文介绍了一段用于获取用户在网页上所选文本的JavaScript脚本。该脚本兼容多种浏览器环境,包括现代浏览器及IE等旧版浏览器。通过检测不同浏览器的选择API,确保能够准确捕获用户的文本选择,并将其应用于相应功能。
1万+

被折叠的 条评论
为什么被折叠?



