我无法使表格正确显示。我使用HP echo语句创建表-4列,最多几百行。我只想在任何时候显示表的20行。因此,我创建了完整大小的表,然后为了初始化,我使用一个js函数调用,首先为所有行调用css(display:none),然后为我希望显示的数组中的20个连续行中的每一行调用css(display:table)。
Thead的HTML:
<thead>
<tr>
<th>
<div class='title'>Fiddle Tunes Collection (<? echo sizeof($pml_arr); ?>) </div>
</th>
<th class='key' >Key</th>
<th class='mode'>Mode</th>
<th id="TS" class='type'>Tune/Song</th>
</tr>
</thead>
tBody的php:
foreach ($pml_arr as $row => $cell) {
$item = $row + 1;
echo "<tr id='row" . $row . "'>" ;
echo "<td>";
echo "<div class='title'> ";
echo "$item";
echo ") ";
echo "$cell[0] ";
echo "</div> ";
echo "</td>";
echo "<td class='key'>$cell[1]</td>" ;
echo "<td class='mode'>$cell[2]</td>" ;
echo "<td class='type'>$cell[3]</td>" ;
echo "</tr>" ;
}
JS:
function initTblDisp() { // alert("View the full array in the table");
$(document).ready (function () {
$("tbody > tr").css ("display", "none");
var i=0; var row_id;
while (i<20) {
row_id = ("row" + i);
$("#" + row_id).css ("display", "table");
i++;
}
});
}
div class=“title”的css:
.title { width:55%; text-align:left; padding-left:4px;
padding-right:4px; display:inline; white-space:no-wrap; overflow:hidden; }
前2 TR的回显php(来自“视图源”):
<tr id='row0'>
<td> <div class='title'> 1) Boys of Bluehill </div> </td>
<td class='key'>D</td><td class='mode'>major</td>
<td class='type'>T</td>
</tr>
<tr id='row1'>
<td><div class='title'> 2) Cluck Old Hen </div> </td>
<td class='key'>A</td>
<td class='mode'>Dorian</td>
<td class='type'></td>
</tr>
thead和tbody是兄弟姐妹,是table的子代。
主要问题是tbody cols在js调用后失去了它们的width样式。提示:
>
如果我在alert()
处暂停js,我会看到完整的表,其中4个cols被格式化为thead和tbody的正确col宽度。(但第一列中的.title div是“中心”对齐的,而不是我所期望的“左”对齐的。)
当我让js完成时,我会看到文件的前20行,但tbody中的所有col都失去了它们的宽度样式,并恢复到基于td内容宽度的默认浏览器col宽度,但thead宽度样式保持正常。
在花了几天的时间在这里和其他地方寻找暗示,但却一无所获之后,我已经没有选择了。我将非常感谢一些不像我现在那么红的新眼睛的帮助。(我希望作为我的第一个问题,我没有在这里提出太多。它可能是一个愚蠢的简单的问题。)
尝试将行显示设置为“表-行”而不是“表”。