javascript - 数据表:How to control the <th> width of table .我正在使用Jquery -1.9.4版本

标签 javascript jquery jquery-ui user-interface datatables

是否可以控制或设置添加到表头作为行 css 的宽度。我试图从版本 1.9.4 的 dataTables-jquery 中检查它。但找不到任何解决方案。由于宽度的增加,对齐受到干扰。

我还在 HTML 中分配宽度,例如

<th width="20%">Bhairav</th>

但是当我检查控制台时,它看起来像

<th width="20%" class="sorting_disabled" role="columnheader" rowspan="1" colspan="1" aria-label="" style="width: 12px;">Bhairav</th>

问题是 style="width: 12px;"正在从任何地方动态添加到它。?

谁能帮我解决这个问题吗?

最佳答案

style="width: 12px;"当 dataTables 有 bAutoWidth: true 时添加。示例:

dataTables 1.9.4,默认 bAutowidth (真)-> <强> http://jsfiddle.net/rrsn0ckL/

第一<th>呈现为

<th width="30%" class="sorting_asc" ...style="width: 254px;">Rendering engine</th>

bAutoWidth: false同表-> <强> http://jsfiddle.net/rrsn0ckL/1/

第一<th>呈现为

<th width="30%" class="sorting_asc" ...>Rendering engine</th>

所以使用bAutoWidth: false避免 style="width: 12px;"

<小时/>

通知:<th> width属性是 HTML 4.01 特定的,不应再使用 -> https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th

而是使用 CSS 或内联样式 style="width:20%;" 。 CSS 示例:

table#example th:nth-child(1) {
    width: 20%;
}
table#example th:nth-child(2) {
    width: 20%;
}

等等

关于javascript - 数据表:How to control the <th> width of table .我正在使用Jquery -1.9.4版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30504210/

相关文章:

javascript - 如果存在子菜单,如何将跨度 append 到 <li>

javascript - 用es6写书架模型

javascript - 从父级和子级 Http 请求获取可观察数据

javascript - 是否有用于操作日期的 jQuery 时间/日历插件?

javascript - 以小时和分钟为单位的范围 slider javascript

javascript - jQuery - 获取子级 CSS 反向旋转的父级 Angular 差异

jquery - 如何使用 jQuery 读取背景图片 URL?

javascript - 为什么 jQuery 的 $.makeArray 忽略字符串键?

jQuery-UI 对话框按钮 - 将参数传递给 btn click 函数

css - 在 foursquare.com 上执行 'Recent Activity' 效果的页面小部件或插件?