后台管理系统中主要以表格为主,表格溢出问题是很常见的,为了不影响代码结构有能轻松解决表格溢出问题,可以使用 `table_fixed` 方法:
```
function table_fixed(selector,width) {
$obj = $(selector);
//未设置宽度自动获取width属性的宽
if (typeof width === "undefined"){
width = 0;
$obj.find("tr:first th").each(function () {
width += parseInt($(this).attr("width") || $(this).innerWidth());
})
}
$obj.css({"width":width+"px","table-layout":"fixed"});
$obj.wrap('');
}
```
使用方法如下:
```
table_fixed('.table'); //使用宽度自动识别,首先识别表格中th的width值,然后识别真实宽度
table_fixed('.table',2000);//直接将表格设置为2000,让表格溢出
```