比如针对用户浏览器的不同载入相应的css文件

解决方案 »

  1.   

    <!--[if IE 6]>
    <link rel="stylesheet" type="text/css" href="css/header4.css" />
    <![endif]-->
    <!--[if IE 7]>
    <link rel="stylesheet" type="text/css" href="css/header3.css" />
    <![endif]-->
    <!--[if IE 8]>
    <link rel="stylesheet" type="text/css" href="css/header2.css" />
    <![endif]-->
    <!--[if !IE]>
    <link rel="stylesheet" type="text/css" href="css/header1.css" />
    <![endif]-->
      

  2.   

    先判断 . jsvar style = document.createElement('link');
    style.href = 'css.css';
    style.rel = 'stylesheet';
    style.type = 'text/css';
    document.getElementsByTagName('HEAD')[0].appendChild(style);
      

  3.   

    先判断浏览器 然后style.href 加载不同的css 
      

  4.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <script language="javascript">
    function check(){
    if(window.navigator.userAgent.indexOf("MSIE 8.0")>=1){
    //如果浏览器为IE 8.0
    alert("ie8");
    }
    else if(window.navigator.userAgent.indexOf("MSIE 7.0")>=1){
    //如果浏览器为IE 7.0
    setActiveStyleSheet("IE7.0_index_layout.css");//设置css样式表
    }
    else if(window.navigator.userAgent.indexOf("TencentTraveler")>=1){
    //如果浏览器为腾讯TT
    setActiveStyleSheet("TT_index_layout.css");
    }
    else if(window.navigator.userAgent.indexOf("Maxthon")>=1){
    //如果浏览器为傲游
    setActiveStyleSheet("Maxthon_index_layout.css");
    }
    else if(window.navigator.userAgent.indexOf("MSIE 6.0")>=1){
    //如果浏览器为IE 6.0
       alert("ie6");
    }
    else if(window.navigator.userAgent.indexOf("Firefox")>=1){
    //如果浏览器为Firefox
    alert("Firefox");
    setActiveStyleSheet("FF_index_layout.css");
    }
    else if(window.navigator.userAgent.indexOf("Safari")>=1){
    //如果浏览器为Safari
    setActiveStyleSheet("Safari_index_layout.css");
    }
    else if(window.navigator.appName=="Opera"){
    //如果浏览器为Opera
    setActiveStyleSheet("Opera_index_layout.css");
    }
    else{
    //如果浏览器为其它
    setActiveStyleSheet("default_index_layout.css");
    }
    }</script>
    <body onload="check()">
    <div class="main">Hello Word!Hello Word!Hello Word!</div>
    </body></html>