Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在IE7和IE6中,设置element.style[';display';]=';继承';这是个例外_Javascript_Css_Internet Explorer - Fatal编程技术网

Javascript 在IE7和IE6中,设置element.style[';display';]=';继承';这是个例外

Javascript 在IE7和IE6中,设置element.style[';display';]=';继承';这是个例外,javascript,css,internet-explorer,Javascript,Css,Internet Explorer,对于这个IE bug,有什么好的解决方法可以让我在IE7或IE6中使用javascript将HTML元素的显示样式设置为“继承”呢 var el = document.getElementById('someElementID'); if (!el) return false; try { var displayValue = 'inherit'; //the next line throws exception in IE7 and IE

对于这个IE bug,有什么好的解决方法可以让我在IE7或IE6中使用javascript将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);
    }

假设我不想将
可见:隐藏
位置:绝对
设置为不可见,或
z索引
设置为其他项下

css2中添加了许多
display
属性的值,
inherit
就是其中之一。旧浏览器不支持这些新值。您可以比较和中可能的值


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

display:inherit
?你需要这个做什么?
display
在某种意义上已经被“继承”:如果你在一个元素上设置了
display:none
,所有的子元素都会被隐式隐藏……这意味着如果你想继承
display
属性,就要这样做:
el.style.display=''我不介意浏览器忽略它,就像抛出异常一样。事实证明,在所有允许的CSS2显示属性中,inherit是IE6和IE7中唯一引发异常的属性。好的,谢谢你们的帮助,伙计们!