在HTML DOM模型中,节点没有offsetWidth、clientWidth、属性,为什么却可以再js中调用呢?

解决方案 »

  1.   

    这些是DOM节点的property。 不是 HTML标签的 attribute
      

  2.   

    请看完HTML DOM模型http://www.w3cschool.cn/dom_obj_window.html
      

  3.   

    HTML DOM 指的是文档模型,只表示数据结构。offsetWidth、clientWidth是页面渲染后的视觉呈现(大小,位置,颜色,状态等)
      

  4.   

    非常感谢大侠们的积极帮助,再次感谢,,还有个一个问题是:为什么  document.body.offsetHeight  和  document.body.clientHeight得出值是一样的啊?
      

  5.   

    你把body的border属性设置大于0,就会发现他们的不同了
      

  6.   


    function getScreenSize(target)
    {
        var theWidth,theHeight;
        if (target.innerWidth) 
        { 
        theWidth = target.innerWidth 
        theHeight = target.innerHeight 
        } 
        else if (target.document.compatMode=='CSS1Compat') 
        { 
        theWidth = target.document.documentElement.clientWidth 
        theHeight = target.document.documentElement.clientHeight 
        } 
        else if (target.document.body) 
        { 
        theWidth = target.document.body.clientWidth 
        theHeight = target.document.body.clientHeight 
        } 
        var result = [theWidth,theHeight];
        return result;
    }var width = getScreenSize(window)[0];
    var height=getScreenSize(window)[1];
    alert("宽:"+width+",高:"+height);