div 没有设置height 内容撑大···怎么获取高度啊, clientHeight offsetHeight style.height 都不行

div 没有设置height 内容撑大···怎么获取高度啊, clientHeight offsetHeight style.height 都不行,第1张

如果你想固定高度,设置width(宽度)height(高度)display:block(成块) float:left(左浮动)和 overflow:hidden(禁止溢出)属性。应该就可以了

超出固定高度显示滚动条,只要设置style属性中的overflowY="scroll";

documentgetElementById('scroll')styleoverflowY="scroll";

获取div的高度,如果获取不到,可用下面的方法,一下方法是获取div的编辑完成后的高度:

/

   obj:需要获取属性的html对象

   prop:需要获取的obj对象的属性

  /

function getCurrentStyle (obj, prop) { 

    if (objcurrentStyle) {       

        return objcurrentStyle[prop];     

    }      

    else if (windowgetComputedStyle) {        

        propprop = propreplace (/([A-Z])/g, "-$1");           

        propprop = proptoLowerCase ();        

        return documentdefaultViewgetComputedStyle (obj,null)[prop];     

    }      

    return null;   

}   

var div = documentgetElementsByTagName("div")[0];

var height = getCurrentStyle(div,"height");

用jQuery

$('div')offset()top 是浏览器顶部距离

$("div")width(); div宽度

$("div")html() 内容

//获取id="div"的高度

documentgetElementById("div")styleheight//设置id="div"的高度

documentgetElementById("div")styleheight="200px";

以上就是关于div 没有设置height 内容撑大···怎么获取高度啊, clientHeight offsetHeight style.height 都不行全部的内容,包括:div 没有设置height 内容撑大···怎么获取高度啊, clientHeight offsetHeight style.height 都不行、js判断div高度。、如何获取div距离浏览器顶部的高度,宽度,内容等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9672082.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-30
下一篇2023-04-30

发表评论

登录后才能评论

评论列表(0条)

    保存