做小项目遇到,以前做的一直没有兼容IE6,然后网上找了点资料,实现了IE6的兼容

代码如下

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  2. <html xmlns="http://www.w3.org/1999/xhtml"> 
  3. <head> 
  4.     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> 
  5.     <title></title> 
  6.     <script type="text/javascript" src="script/jquery-1.8.2.min.js"></script> 
  7.     <script type="text/javascript"> 
  8.          //回到顶部  
  9.         //设置滚动条响应事件  
  10.         $(document).ready(function (){  
  11.             $(window).scroll(function () {  
  12.             //拿到滚动条滚动的距离  
  13.             var a = $(window).scrollTop();  
  14.  
  15.             if (a > 0) {  
  16.                 $("#to_top").css("display", "block");  
  17.             } else {  
  18.                 $("#to_top").css("display", "none");  
  19.             }  
  20.             });  
  21.             $('#to_top').click(function () { $('html,body').animate({ scrollTop: '0px' }, 800); return false; });  
  22.         });  
  23.     </script> 
  24.     <style type="text/css"> 
  25.         #content{  
  26.             height:3000px;  
  27.         }  
  28.         #to_top{  
  29.             width:46px;  
  30.             height:46px;  
  31.             font-size:30px;  
  32.             line-height:60px;  
  33.             text-align:center;  
  34.             position:fixed;  
  35.             _position:absolute;  
  36.             left:50%;  
  37.             color:#fff;  
  38.             margin-left:520px;  
  39.             bottom:140px;  
  40.             cursor:pointer;  
  41.         }   
  42.         #to_top a{  
  43.             color:#fff;  
  44.             width:80px;  
  45.             height:80px;  
  46.             display:inline-block;  
  47.         }  
  48.     </style> 
  49. </head> 
  50. <body> 
  51.     <div id="content"> 
  52.           
  53.     </div> 
  54.     <!--回到顶部--> 
  55.     <!--[if IE 6]> 
  56.     <style type="text/css"> 
  57.         html{_text-overflow:ellipsis}  
  58.         #to_top{_position:absolute;_top:expression(eval(document.documentElement.scrollTop + 300))}  
  59.     </style> 
  60.     <![endif]--> 
  61.     <div id="to_top" style="display:none;">    
  62.         <a href="#go_top"><img src="p_w_picpaths/top.gif" alt="回到顶部" title="回到顶部" /></a> 
  63.     </div> 
  64.       
  65. </body> 
  66. </html> 

其中<!--[if IE 6]>
 

  1. <!--[if IE 6]> 
  2.     <style type="text/css"> 
  3.         html{_text-overflow:ellipsis}  
  4.         #to_top{_position:absolute;_top:expression(eval(document.documentElement.scrollTop + 300))}  
  5.     </style> 
  6.     <![endif]--> 

做的是IE6的兼容,返回顶部的时间都可以自己在js代码里设置。