Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/42.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 将不同的css加载到IE_Javascript_Css_Internet Explorer_Conditional - Fatal编程技术网

Javascript 将不同的css加载到IE

Javascript 将不同的css加载到IE,javascript,css,internet-explorer,conditional,Javascript,Css,Internet Explorer,Conditional,因此,如果检测到IE,我将尝试加载不同的css样式表 我的代码: <head> <!-- other scripts and stylesheets --> <!--[if IE]> <link href='css/index_ie.css' rel='stylesheet' type='text/css'> <![endif]--> <!--[if !IE]> <link href='css/index.c

因此,如果检测到IE,我将尝试加载不同的css样式表

我的代码:

<head>
<!-- other scripts and stylesheets -->

<!--[if IE]>
  <link href='css/index_ie.css' rel='stylesheet' type='text/css'>
<![endif]-->
<!--[if !IE]>
  <link href='css/index.css' rel='stylesheet' type='text/css'>
<![endif]-->

<script>
(function() {
    if (typeof ActiveXObject === "undefined") {
        var s = document.createElement('link');
        s.href = "css/index.css";
        s.rel = "stylesheet";
        s.type = "type/css";
        document.documentElement.appendChild(s);
    }
    else {
        var s = document.createElement('link');
        s.href = "css/index_ie.css";
        s.rel = "stylesheet";
        s.type = "type/css";
        document.documentElement.appendChild(s);
    }
})();
</script>
</head>

(功能(){
如果(ActiveXObject的类型==“未定义”){
var s=document.createElement('link');
s、 href=“css/index.css”;
s、 rel=“样式表”;
s、 type=“type/css”;
document.documentElement.appendChild;
}
否则{
var s=document.createElement('link');
s、 href=“css/index_ie.css”;
s、 rel=“样式表”;
s、 type=“type/css”;
document.documentElement.appendChild;
}
})();
当不是IE浏览器时,这将正确加载
index.css
。但是,在使用ie时,这不是加载
索引ie.css


注:使用IE 10进行测试要在IE 9及以上版本以外的浏览器中包含内容,请使用:


正如它所解释的:

下层显示的条件注释使您能够在不识别条件注释的浏览器中包含内容。尽管条件注释本身会被忽略,但其中的HTML内容不会被忽略

但是,请注意,IE 9之后不完全支持条件注释(从同一页面的顶部):

重要信息从Internet Explorer 10开始,标准模式不再支持条件注释。使用功能检测来提供浏览器不支持的网站功能。有关标准模式的详细信息,请参见


对于IE,使用这个
var s=document.createElement(“”)
另外,将其附加到
元素中
document.getElementsByTagName(“head”)[0]。appendChild
。尝试了该操作,但未成功。
<![if IE]>
  <link href='css/index.css' rel='stylesheet' type='text/css'>
<![endif]>