<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<style>
#t{border-width:medium;}
</style>
<table width="100" id="t" border="10">
<tr>
<td>1</td>
<td>1</td>
</tr>
</table>
<table width="100" id="t2" border="10">
<tr>
<td>1</td>
<td>1</td>
</tr>
</table>
<script>
alert(t.currentStyle.borderLeftWidth)
alert(t2.currentStyle.borderLeftWidth)
</script>
</body>
</html>
例如这样如何获取准确的边框宽度
ff可以用getComputedStyle
ie有什么办法
例子中判断currentStyle会得到medium(3px)
但如果我没有设置border-width那就应该取border属性的值,最大的问题是这时判断currentStyle也是得到medium(默认值)
有什么办法准确判断呢

解决方案 »

  1.   

    this?<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <body>
    <table width="100" id="t" border="10">
        <tr>
            <td>1</td>
            <td>1</td>
        </tr>
    </table>
    <table width="100" id="t2" border="10">
        <tr>
            <td>1</td>
            <td>1</td>
        </tr>
    </table>
    <script>
    alert(t.border)
    alert(t2.border)
    </script>
    </body>
    </html>
      

  2.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <body>
    <style>
    #t{border-width:medium;}
    </style>
    <table width="100" id="t" border="10">
        <tr>
            <td>1</td>
            <td>1</td>
        </tr>
    </table>
    <table width="100" id="t2" border="10">
        <tr>
            <td>1</td>
            <td>1</td>
        </tr>
    </table>
    <script>
    alert(t.offsetWidth-t.clientWidth)
    alert(t2.offsetWidth-t2.clientWidth)
    </script>
    </body>
    </html>cloudgamer去我blog参考下我转的一篇文章.
    http://blog.csdn.net/natineprince/archive/2009/04/30/4138260.aspx
      

  3.   

    你要先判断下 ,如果用style取不到再实用 currentStyle
      

  4.   

    问题即使不设样式
    也能用currentStyle取到默认值medium
    所以才判断不了到底有没有设
      

  5.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <body>
    <style>
    #t{border-width:4px;}
    </style>
    <table width="100" id="t" border="10">
        <tr>
            <td>1</td>
            <td>1</td>
        </tr>
    </table>
    <table width="100" id="t2" border="20">
        <tr>
            <td>1</td>
            <td>1</td>
        </tr>
    </table>
    <script>
    alert(t.offsetWidth-t.clientWidth)
    alert(t2.offsetWidth-t2.clientWidth)
    </script>
    </body>
    </html>
    你再试试是不是两倍?!
    看看又不会亏的...
    当我害你么...
      

  6.   


    你先用 style 取下 ,如果取到了 , 不说明 设定值了吗?
      

  7.   

    其实我是为了蹭分。
    function $(id) { return document.getElementById(id); }
    alert(($("t").offsetWidth - $("t").clientWidth) / 2);
    alert(($("t2").offsetWidth - $("t2").clientWidth) / 2);