读书人

这段代码在IE7上为什么达不到效果?该怎

发布时间: 2012-03-23 12:06:21 作者: rapoo

这段代码在IE7上为什么达不到效果??
<html>
<head>
<title>
document.getSelection方法
</title>
<script language="javascript">
function showSelection(){
document.forms[0].selectedText.value=document.getSelection()
}
document.captureEvents(Event.MOUSEUP)
document.onmouseup=showSelection
</script>
</head>
<body>
<b>请选中页面中的一些文本</b>
<hr>
<p>
这都是用来测试的文本,您可以用鼠标来选中,然后试一试选择文本后产生的结果.
</p>
<form>
<textarea name="selectedText" rows=3 cols=40 wrap="virtual">
</textarea>
</form>
</body>
</html>

-------------------------------
上面代码在IE7上看不到效果,而在firefox上可以...为什么呢?谢谢!!

[解决办法]
没用过这东西,查了半天手册...

JScript code
function   showSelection(){     var o = document.forms[0].selectedText, r;        if (window.getSelection) {        o.value = o.value.substring(o.selectionStart, o.selectionEnd);    } else {        o.value = document.selection.createRange().text;    }    window.setTimeout(function () {        o.focus();        o.select();    }, 0);} document.onmouseup = showSelection;
[解决办法]
JScript code
function   showSelection(){ 
if(document.getSelection)
document.forms[0].selectedText.value=document.getSelection() ;
else
document.forms[0].selectedText.value=document.selection.createRange().text
}
//document.captureEvents(event.mouseUp)
document.onmouseup=showSelection ;

读书人网 >JavaScript

热点推荐