在IE7和IE6中,设置element.style ['display'] ='inherit'会产生异常

时间:2010-08-22 16:23:24

标签: javascript css internet-explorer

这个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: hiddenposition:absolute设置在视野之外,或z-index设置其他内容。

1 个答案:

答案 0 :(得分:3)

CSS 2中添加了display属性的大量值,inherit就是其中之一。较旧的浏览器不支持这些新值。您可以比较CSS 1CSS 2中的可能值。

即使您可以设置该值,它也毫无用处,因为浏览器不知道如何处理它。