我有一个关于可用性/设计的问题。
目前,我正在使用一些jQuery来隐藏/显示整个区域。目前这些都在一个大表格中,顶部为主标题的thead,其后是第二个thead,它是要显示的标题。接下来是另一个thead,它是隐藏内容的标题,该内容显示在tbody中。
我知道这是可怕的风格,但我想要解决的问题是,我希望所有行都相同,因为它们都显示相同类型的数据。
代码示例:
PS:如果感兴趣,下面是我用于整个事情的JQuery。
代码示例:
<table id="report">
<thead>
<tr id="header">
<th>Country</th>
<th>Population</th>
<th>Area</th>
<th>Official languages</th>
<th></th>
</tr>
</thead>
<thead>
<tr>
<td>United States of America</td>
<td>306,939,000</td>
<td>9,826,630 km2</td>
<td>English</td>
<td><div class="arrow"></div></td>
</tr>
</thead>
<thead>
<tr>
<td>First Row</td>
<td>Second Row</td>
<td>Third Row</td>
<td>Fourth Row</td>
<td>Fifth Row</td>
</tr>
</thead>
<tbody>
<tr>
<td colspan="5">
<img src="../125px-Flag_of_the_United_States.svg.png" alt="Flag of USA" />
<h4>Additional information</h4>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Usa">USA on Wikipedia</a></li>
<li><a href="http://nationalatlas.gov/">National Atlas of the United States</a></li>
<li><a href="http://www.nationalcenter.org/HistoricalDocuments.html">Historical Documents</a></li>
</ul>
</td>
</tr>
<tr><td>some other stuff</td></tr>
</tbody>
</table>
以下是显示的内容:
alt text http://img694.imageshack.us/img694/9773/screenshot20100708at100.png
alt text http://img822.imageshack.us/img822/9206/screenshot20100708at101.png
我之所以这样做,是因为通常情况下,实际可显示标题(本例为国家数据)将有4行,并且只隐藏了3个列头(第一行、第二行等)。此内部数据只有1行是URL,长度可以从10个字符到100+个(常见),这导致整个显示发生变化,我的标题成为2或3行。而我想要的是所有行都保持不变,是否有办法仅将一个tbody与一个table中的thead关联起来,以便不影响其他任何tbody。由于这可能会相当令人困惑,是否有更好的方法来实际上拥有多个表格,但每个表格的thead无论放入什么数据,都应保持不变。
我知道肯定会有疑问,但是任何帮助都将不胜感激,请注意我完全可以采用不同的方式进行操作。但是需要隐藏数据,这是一个具有表头的表格。可以有一个可显示的部分,与其不匹配(可以是div),每个部分内的数据格式都应保持不变。PS:如果感兴趣,下面是我用于整个事情的JQuery。
<script type="text/javascript">
$(document).ready(function(){
$("#report thead").children("tr:odd").not("#header").addClass("odd");
$("#report thead").children("tr:odd").not("#header").each(function(index){$(this).attr("id", "id" + index);});
$("#report thead").children("tr:even").not("#header").addClass("bodyhead");
$("#report thead:even").not(":first-child").each(function(index){$(this).attr("id", "bhid" + index);});
$("#report tbody").each(function(index){$(this).attr("id", "bid" + index);});
//$("#report tbody").each(function(index){$(this).attr("id", "id" + index);});
//$("#report tbody").children("tr:not(.odd)").hide();
$("#report tbody").hide();
$("#report thead:even").not(":first-child").hide();
//$("#report tbody #id0").show();
//For header of headers.
$("#report thead").children("tr:first-child").show();
$("#report thead").children("tr").not("#header").not(".bodyhead").click(function(){
$("#report #b" + this.id).toggle();
$("#report #bh" + this.id).toggle();
$(this).find(".arrow").toggleClass("up");
});
});
</script>
table-layout: auto
和table-layout: fixed
之间的区别?我找不到一个稳定清晰的解释,包括两者的用例。我找到了这个https://css-tricks.com/fixing-tables-long-strings/,但它只展示了例子,没有详细解释发生了什么。 - tonix