我看过: Understanding offsetWidth, clientWidth, scrollWidth and -Height, respectively
但事实并非如此。例如,
.main {
width: 400px;
overflow: visible;
}
.main table {
width: 600px;
}
<div class="main">
<table>
<thead><tr><th>Foo</th><th>Bar</th></tr></thead>
<tbody>
<tr><td>Row1</td><td>Hello</td></tr>
<tr><td>Row2</td><td>World</td></tr>
</tbody>
</table>
</div>
---------------------------------------
|main |
| ----------------------------------------------------
| | table |
| ----------------------------------------------------
| |
| |
---------------------------------------
答案 0 :(得分:0)
似乎对我有用吗?
http://codepen.io/anon/pen/EZEzGB
alert("Scrollwidth: " + document.getElementById('main').scrollWidth + "OffsetWidth: " + document.getElementById('main').offsetWidth);
您使用的是返回错误值?