<!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(默认值)
有什么办法准确判断呢
<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(默认值)
有什么办法准确判断呢
<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>
<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
也能用currentStyle取到默认值medium
所以才判断不了到底有没有设
<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>
你再试试是不是两倍?!
看看又不会亏的...
当我害你么...
你先用 style 取下 ,如果取到了 , 不说明 设定值了吗?
function $(id) { return document.getElementById(id); }
alert(($("t").offsetWidth - $("t").clientWidth) / 2);
alert(($("t2").offsetWidth - $("t2").clientWidth) / 2);