首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

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

2012-03-23 
这段代码在IE7上为什么达不到效果??htmlheadtitledocument.getSelection方法/titlescript langua

这段代码在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 ;

热点排行