IE8不动态应用css显示
IE8 doesn't apply css display dynamically
我正在尝试开发一个表,在给定值上隐藏其列。我正在使用另一个问题中讨论的解决方案。作为建议的一部分,他们说,为了支持ie8浏览器,应该使用隐藏规则,而不是默认显示。(我的浏览器处于怪癖模式)。
我有几个隐藏规则,如下所示:
table.Show1 .cellType2, table.Show1 .cellType3{
display:none;
}
所以我期望的是cellType2
和cellType3
隐藏时,表的className
是动态变化的。对于初始值,它工作得很好,但是当表的className动态更改时,它隐藏了所需的单元格,但它不会将其他单元格带回来。
我用IE开发人员工具检查了它,我知道表的className设置正确。我还检查了cell元素的样式,没有显示规则集,所以我希望显示为默认值,但它不是(它没有显示)。
我发现最烦人的是,如果我改变任何样式属性在开发人员工具中,它会意识到它应该显示单元格,然后,它把它带回来。
为什么不应用样式?请帮我解决这个问题。
编辑:我包含一个"最小"代码来重新创建这个问题。
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>
听起来好像不是重新粉刷桌子。有几个ie7 &重新油漆和回流奇怪的地方…
你可以尝试在javascript中强制重新绘制,也许只是通过隐藏和显示表格,如
document.getElementById('myTable').style.display='none';
document.getElementById('myTable').style.display='table';
或使用
之类的内容强制整个页面回流document.body.className=document.body.className;
在尝试重新绘制单元格时似乎存在问题。仅仅从CSS规则不工作,但如果我们直接在JavaScript中应用显示,那么单元格被正确绘制。循环遍历单元格并直接应用样式就可以了,我只需要有一个名称约定来轻松识别单元格应该属于的类。
if(isEmpty(cell.className)|| cell.className == (selectedType+"_cell"))
{
cell.style.display = 'table-cell'; // might be different for other IE versions
}
else
{
cell.style.display = 'none';
}
相关文章:
- 无法使用Javascript和CSS显示/隐藏
- jQuery隐藏元素在使用CSS显示时保持隐藏状态
- 使用 JavaScript 和 CSS 显示图像
- CSS显示会影响jQuery/Javascript
- 脚本点击Css显示属性更改不正常运行Asp.net
- 使用css显示和隐藏元素不起作用
- Pandoc将HTML导出到带有CSS显示的Word:没有不起作用
- 使用CSS显示所有字符的内容可编辑单行
- 为什么javascript+CSS显示设置会使单选按钮不受欢迎
- 使用Javascript,如何在不同的HTML页面上更改CSS显示属性
- 使用 jQuery/CSS 显示/隐藏选定的表单
- CSS 显示属性不起作用
- 如何使用 JavaScript 更改 CSS 显示属性
- 通过图像和 CSS 显示背景网格
- 单击按钮时,使用 css 显示图像
- Jquery移动页面在使用css显示图像后消失
- 使用 CSS 显示隐藏项
- 当 CSS 显示“无要阻止”时,对象标记将重新加载
- 为什么我的 css 显示不规则
- 过滤器:第 n 个子项忽略 css 显示为无的位置