我想你正在寻找这样的东西:
工作示例
CSS
table {
border:1px solid blue;
}
.table1 td {
border:1px solid red;
height:50px;
width:50px;
}
.table2 td {
height:50px;
border: 1px solid green;
}
HTML
<table class="table1">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</table>
<table class="table2">
<td></td>
<td></td>
<td></td>
</table>
jQuery
var width = function () {
$('.table2').width($('.table1').width());
};
$(document).ready(width);
$(window).resize(width);
如果您更喜欢纯 JavaScript:
工作示例2
function tablewidth() {
var table1 = document.getElementById('table1'),
style = window.getComputedStyle(table1),
width = style.getPropertyValue('width'),
border = style.getPropertyValue('border-left-width'),
w = parseInt(width, 10) + parseInt(border, 10) * 2 + 'px';
document.getElementById('table2').style.width = w;
}
window.onresize = tablewidth;
window.onload = tablewidth;