统一用它吧: document.documentElement.scrollTop

解决方案 »

  1.   

    这样取出来的值是0,就不成了
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <html>
    <head>
        <title>++</title>
    </head>
    <body onclick="cc()">
    <script language="javascript" type="text/javascript">
    function cc(){
        alert(document.documentElement.scrollTop);
    }
    </script>
    <table>
    <tr>
    <td height="6000"></td>
    </tr>
    </table>
    </body>
    </html>
      

  2.   

    在HTML文件头部声明了这样一句:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd">
    改成这样
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">这是IE5与IE6的区别:
    var scrollPos; 
    if (typeof window.pageYOffset != 'undefined') { 
       scrollPos = window.pageYOffset; 

    else if (typeof document.compatMode != 'undefined' && 
         document.compatMode != 'BackCompat') { 
       scrollPos = document.documentElement.scrollTop; 

    else if (typeof document.body != 'undefined') { 
       scrollPos = document.body.scrollTop; 

    alert(scrollPos);还有改好方法就是
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "' target=_new>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      

  3.   

    var PosTyle = {
    //Page
    getBodyWidth : function()
    {
    return document.documentElement.clientWidth || document.body.clientWidth || 0;
    },
    getBodyHeight : function()
    {
    return document.documentElement.clientHeight || document.body.clientHeight || 0;
    },
    getBodyLeft : function()
    {
    return document.documentElement.scrollLeft || document.body.scrollLeft || 0;
    },
    getBodyTop : function()
    {
    return document.documentElement.scrollTop || document.body.scrollTop || 0;
    },
    getBody : function()
    {
    return {
    width : this.getBodyWidth(),
    height : this.getBodyHeight(),
    left : this.getBodyLeft(),
    top : this.getBodyTop()
    };
    },
    getScreenWidth : function()
    {
    return window.screen.width;
    },
    getScreenHeight : function()
    {
    return window.screen.height;
    }, //Element
    getElementWidth : function(o)
    {
    (typeof o == "string") ? o = $(o) : "";
    return o.offsetWidth;
    },
    getElementHeight : function(o)
    {
    (typeof o == "string") ? o = $(o) : "";
    return o.offsetHeight;
    },
    getElementLeft : function(o)
    {
    if (o == null)
    {
    return 0;
    } (typeof o == "string") ? o = $(o) : "";
    return (o.offsetLeft + this.getElementLeft(o.offsetParent));
    },
    getElementTop : function(o)
    {
    if (o == null)
    {
    return 0;
    } (typeof o == "string") ? o = $(o) : "";
    return (o.offsetTop + this.getElementTop(o.offsetParent));
    },
    getElement : function(o)
    {
    return {
    width : this.getElementWidth(o),
    height : this.getElementHeight(o),
    left : this.getElementLeft(o),
    top : this.getElementTop(o)
    };
    },
    getBorderLeft : function(o)
    {
    return parseInt(this.getCurrentStyle(o, "borderLeftWidth"));
    },
    getBorderTop : function(o)
    {
    return parseInt(this.getCurrentStyle(o, "borderTopWidth"));
    },
    getBorderRight : function(o)
    {
    return parseInt(this.getCurrentStyle(o, "borderRightWidth"));
    },
    getBorderBottom : function(o)
    {
    return parseInt(this.getCurrentStyle(o, "borderBottomWidth"));
    },
    getBorder : function(o)
    {
    return {
    left : this.getBorderLeft(o),
    top : this.getBorderTop(o),
    right : this.getBorderRight(o),
    bottom : this.getBorderBottom(o)
    };
    }, //Style
    getCurrentStyle : function(o, s)
    {
    (typeof o == "string") ? o = $(o) : ""; if (o.currentStyle)
    {
    return o.currentStyle[s];
    }
    else if (document.defaultView.getComputedStyle)
    {
    return document.defaultView.getComputedStyle(o, '').getPropertyValue(s.replace(/([A-Z])/g, '-$1').toLowerCase());
    }
    else
    {
    return o.style[s];
    }
    },
    setStyle : function(o, s, v)
    {
    (typeof o == "string") ? o = $(o) : ""; if (Browser.moz && s == "cursor" && v == "hand")
    {
    v = "pointer";
    } o.style[s] = v;
    }
    };