我想隐藏/取消隐藏某个表格单元或页面,并且我发现隐藏和取消隐藏在Internet Explorer中之前和之后的单元格大小相同,但在Firefox和Chrome中,包含我的标签的单元格更改大小。在Firefox中隐藏/取消隐藏更改单元格大小
我的页面实际上比下面的代码更复杂,但我创建了这个精简版本来尝试和隔离问题,asi它显示了问题而没有其他复杂性。
我也试过style =“display:block;”和style =“display:inline;”取消隐藏元素。
任何人都可以帮助我理解为什么Firefox和Chrome改变了大小?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript">
function hide_them(){
TD_hide_them();
}
function TD_hide_them(){
// hide the TD
count=0;
while(document.getElementById("TD_"+count)){
document.getElementById("TD_"+count).style.display="none";
count++;
}
// hide the Input
count=0;
while(document.getElementById("Input_"+count)){
document.getElementById("Input_"+count).style.display="none";
count++;
}
}
function unhide_them(){
TD_unhide_them();
}
function TD_unhide_them(){
// hide the TD
count=0;
while(document.getElementById("TD_"+count)){
document.getElementById("TD_"+count).style.display="inline";
count++;
}
// hide the Input
count=0;
while(document.getElementById("Input_"+count)){
document.getElementById("Input_"+count).style.display="inline";
count++;
}
}
</script>
<style type="text/css">
TD.MYLabel {
background-color: #99D6EB;
vertical-align: top;
text-align:left;
width: 100px;
}
</style>
</head>
<body>
<p>
<table style="width:600px; background-color: yellow;">
<tr>
<td id="TD_0" class="MYLabel">Label 0</td><td><input type="text" id="Input_0"></td>
</tr>
<tr>
<td id="TD_1" class="MYLabel">Label 1 is longer</td><td><input type="text" id="Input_1"></td>
</tr>
</table>
<input type="button" onclick="hide_them()" value="hide_them">
<input type="button" onclick="unhide_them()" value="unhide_them">
</p>
</body>
</html>
谢谢。完善。这解决了我的问题。根据w3schools.com内联是默认财产,我一直在这个假设。显然,他们对默认值是错误的。非常感谢您的帮助。非常感谢。 – user754809 2011-05-15 21:47:37
如果没有应用其他样式,'inline'是默认值。 UA样式表在所有现代浏览器中将表格单元格样式设置为“display:table-cell”。 – 2011-05-16 14:58:18