我正在尝试开发一个在给定值上隐藏其列的表。我正在使用另一个 SO question中讨论的解决方案。作为建议的一部分,他们说要支持 IE<8 浏览器,应该使用隐藏规则并默认显示。(我的浏览器处于怪癖模式)。
我有几个如下所示的隐藏规则。
table.Show1 .cellType2, table.Show1 .cellType3{
display:none;
}
所以我期望的是在动态更改表cellType2
时cellType3
隐藏。className
使用初始值它可以正常工作,但是当表的类名动态更改时,它会隐藏所需的单元格,但不会将另一个单元格带回来。
我用 IE Developer Tool 完成了它,我知道表的 className 设置正确。我还检查了单元格元素的样式并且没有设置显示规则,所以我希望显示为默认值,但它不是(它不显示)。
我发现最烦人的是,如果我在 Developer Tool 中更改任何样式属性,它会意识到它应该显示单元格,然后将其恢复。
为什么不应用样式?请帮我解决这个问题。
编辑:我包含一个“最小”代码来重新创建问题。
JavaScript:
function typeChanged(name, id)
{
var elem = document.getElementById(id);
elem.className = name;
}
CSS:
table td
{
border-top: 1px none #000066;
border-right: 1px none #000066;
border-bottom: 1px solid #000066;
border-left: 1px solid #000066;
}
table.Show1 .cellType2, table.Show2 .cellType1{
display:none;
}
table.Show1 td,table.Show2 td
{
border-style: solid solid solid solid;
border-width: 1px;
}
table.Show1 th,table.Show2 th,table.Show1,table.Show2
{
background: transparent none repeat scroll 0% 0%;
color: #000066;
border-style: none none none none;
table-layout: fixed;
}
HTML:
<select onChange="typeChanged(this.options[this.selectedIndex].value,'mytable')">
<option value="Show1">Show1</option>
<option value="Show2">Show2</option>
</select>
<table id="mytable" class="Show1">
<tr>
<th class="cellType1">type1</th>
<th class="cellType2">type2-a</th>
<th class="cellType2">type2-b</th>
</tr>
<tr>
<td class="cellType1"><input type="text"></input></td>
<td class="cellType2"><input type="text"></input></td>
<td class="cellType2"><input type="text"></input></td>
</tr>
</table>