日期:2014-05-16  浏览次数:20251 次

帮我解说下面一段代码!
var   w3c=(document.getElementById)?   true:   false;
var   agt=navigator.userAgent.toLowerCase();
var   ie   =   ((agt.indexOf( "msie ")   !=   -1)   &&   (agt.indexOf( "opera ")   ==   -1)   &&   (agt.indexOf( "omniweb ")   ==   -1));

function   IeTrueBody(){
return   (document.compatMode   &&   document.compatMode!= "BackCompat ")?   document.documentElement   :   document.body;
}

function   GetScrollTop(){
  return   ie   ?   IeTrueBody().scrollTop   :   window.pageYOffset;
}
-----------------------
代码返回的值得是滚动条的长度,可是我JAVASCRIPT不是很熟悉。
待高手!详解

------解决方案--------------------
var w3c=(document.getElementById)? true: false;
//判断支部支持getElementById,支持true,不支持false
var agt=navigator.userAgent.toLowerCase();
//得到浏览器的情报
var ie = ((agt.indexOf( "msie ") != -1) && (agt.indexOf( "opera ") == -1) &&
(agt.indexOf( "omniweb ") == -1));
//通过这些头部信息来判定是不是ie,还是opera,firefoxd等等
function IeTrueBody(){
return (document.compatMode && document.compatMode!= "BackCompat ")? document.documentElement : document.body;
}
//返回IE的body

function GetScrollTop(){
return ie ? IeTrueBody().scrollTop : window.pageYOffset;
}
//返回body滚动的长度,应为ie和opera这些浏览器他们获取数据的时候方式不太一样,所以两方面都要考虑到