Javascript 需要解决RTL模式下IE6和IE7中span的getBoundingClientRect()无效的问题

Javascript 需要解决RTL模式下IE6和IE7中span的getBoundingClientRect()无效的问题,javascript,internet-explorer,right-to-left,Javascript,Internet Explorer,Right To Left,我正在寻找以下问题的解决方法: 当我尝试使用getBoundingClientRect() 以下代码显示了一个示例: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta

我正在寻找以下问题的解决方法:

当我尝试使用
getBoundingClientRect()

以下代码显示了一个示例:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function show_rectangle()
{
    var el = document.getElementById('hello_id');
    var rec = el.getBoundingClientRect();
    alert('Left:' + rec.left + ' Right:' + rec.right);
}
setTimeout(show_rectangle,2000);
</script>
</head>
<body style="direction:rtl">
<p id='xxx' style="text-align:center"><span id="hello_id" style="border-bottom:dotted 1px">hello</span></p>
</body>
</html>

函数show_rectangle()
{
var el=document.getElementById('hello_id');
var rec=el.getBoundingClientRect();
警报('Left:'+rec.Left+'Right:'+rec.Right');
}
设置超时(显示矩形,2000);
你好

警报在IE6和IE7中均显示为“左:-621右:-593”

当我从主体的样式或跨度的样式属性中删除“direction:rtl”时,我得到了合理的正值


如何解决此问题:即如何在rtl文档中创建带边框的跨距,并具有正确的边界矩形?或者在没有此属性的情况下生成边框?

解决方案是将一个跨距置于另一个跨距内,将边框样式赋予内部跨距,并测量外部跨距:

<p id='xxx' style="text-align:center"><span id="hello_id" ><span style="border-bottom:dotted 1px">hello</span></span></p>

您好

比它更有效