87,990
社区成员
发帖
与我相关
我的任务
分享
<html>
<head>
<title>document.getSeletion方法</title>
<script type="text/javascript">
function showSelection()
{
document.myForm.selectedText.value = document.all ? document.selection.createRange().text:document.getSelection()
}
if(!document.all) document.captureEvents(Event.MOUSEUP)
document.onmouseup = showSelection
</script>
</head>
<body>
<b>选中页面中的一些文字</b>
<hr>
<p>
这些都是用来测试的文字,您可以用鼠标来选中,然后试一试选择文本后产生的效果.
</p>
<form name="myForm">
<textarea name="selectedText" rows=3 cols=40 wrap="virtual">
</textarea>
</form>
</body>
</html>

<script type="text/javascript">
function showSelection()
{
document.myForm.selectedText.value = document.all ? document.selection.createRange().text:document.getSelection()
}
document.onmouseup = showSelection //先绑定
document.captureEvents(Event.MOUSEUP) //再捕获
</script>