<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script>
function onclick(){
scrLeft=window.screenLeft;
scrTop=window.screenTop;
x=event.screenX-scrLeft;
y=event.screenY-scrTop;
rng=document.body.createTextRange();
rng.moveToPoint(x, y);
rng.expand("word");
alert (''+event.clientX+', '+event.clientY+'位置字符为“'+rng.text+'”');
}
document.onclick=onclick;
</script>
</head>
<body>
<div style="position:absolute">
这是一个测试页面==点击这些文字进行测试==当样式为position:absolute时rng.moveToPoint(x, y)会报SCRIPT16389:未指明的错误。
</div>
</body>
</html>
把上面的这段代码保存成htm页面,打开点击任意文字就会报错,但是把position:absolute删掉之后就能正常取得文字,这是什么问题?有什么解决办法吗?