【发布时间】:2010-08-22 16:23:23
【问题描述】:
对于这个 IE 错误有什么好的解决方法,它仍然允许我使用 javascript 在 IE7 或 IE6 中将 HTML 元素的显示样式设置为“继承”?
var el = document.getElementById('someElementID');
if (!el) return false;
try {
var displayValue = 'inherit';
//the next line throws exception in IE7 and IE6
// when displayValue = 'inherit'
// but not for other legit values like 'none', 'block', 'inline' or even ''
el.style['display'] = displayValue;
} catch (e) {
alert(e.message);
}
假设我不想将visible: hidden、position:absolute 设置为不可见或将z-index 设置为其他内容。
【问题讨论】:
-
display: inherit?你需要这个做什么? -
display在某种意义上已经被“继承”了:如果你在一个元素上设置display: none,所有的子元素都被隐式隐藏了。 -
...这意味着如果您希望
display属性被继承,请执行以下操作:el.style.display = '';
标签: javascript css internet-explorer