使用jQuery调整HTML表格单元格宽度 [英] Adjusting HTML Table Cell Width using jQuery
本文介绍了使用jQuery调整HTML表格单元格宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有HTML表格,如下所示。它有七列。我正在使用jQuery调整表格单元格宽度。 jQuery中的总百分比是100。但是,桌子没有占据完整的空间;有一些未使用的空间。如何解决这个问题?
I have HTML table as shown below. It has seven columns. I am adjusting the table cell width using jQuery. The total percentage is 100 in the jQuery. However, the table is not taking the complete space; there is some unused space. How to correct this?
http:/ /jsfiddle.net/Lijo/eFS5J/3/
$(document).ready(function () {
$('#gridDiv').css('width', '630px');
//Set width of table cells
var numberOfColumns = 7;
$('.resultGridTable th, .resultGridTable td').each(function (i) {
$(this).css('background-color', (['Purple', 'Orange', 'Purple', 'Orange', 'Purple', 'Orange', 'Purple'][i % 7]));
if (i % numberOfColumns == 0) {
$(this).css('width', '15%');
}
if (i % numberOfColumns == 1) {
$(this).css('width', '15%');
}
if (i % numberOfColumns == 2) {
$(this).css('width', '15%');
}
if (i % numberOfColumns == 3) {
$(this).css('width', '15%');
}
if (i % numberOfColumns == 4) {
$(this).css('width', '10%');
}
if (i % numberOfColumns == 5) {
$(this).css('width', '15%');
}
if (i % numberOfColumns == 6) {
$(this).css('width', '15%');
}
}
);
}
);
推荐答案
将以下属性添加到您的表格元素中。
Add the following attribute to your table element.
width="100%"
这篇关于使用jQuery调整HTML表格单元格宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文