
<html>
<head>
</head>
<body style="height:400px">
<div id="div1">12312</div>
<script type="text/javascript">
documentgetElementById("div1")styleheight=documentbodystyleheight;
alert(documentgetElementById("div1")styleheight);
//如果body,没有设置样式,这个高度就为空
documentgetElementById("div1")styleheight=documentbodyclientHeight
alert(documentgetElementById("div1")styleheight);
//如果设置了样式,offsetHeight就等于样式的height否则等于clientHeight
documentgetElementById("div1")styleheight=documentbodyoffsetHeight
alert(documentgetElementById("div1")styleheight);
</script>
</body>
</html>
(function(){
var option ={"auto_play":"0","file_id":"16092504232103639705","app_id":"1251580615","width":screenwidth,"height":screenheight}; /调用播放器进行播放/
new qcVideoPlayer( /代码中的id_video_container将会作为播放器放置的容器使用,可自行替换/ "id_video_container", option ); })()
给div设置一个id或者class:
html部分:
<div id="mydiv"></div>
js部分:
<script>
//获取mydiv
var mydiv=documentgetElementById("mydiv");
//获取#mydiv的高度
var divheight=mydivstyleheight;
//设置mydiv行高
mydivstylelineHeight=divheight;
</script>
用clientHeight或offsetHeight。
对于没有具体设置高度的元素,不能直接用height获取高度。
clientHeight表示内容可见区域高度;offsetHeight不同浏览器数值不尽相同,除了clientHeight的高度外还包括边框等的高度。
以上就是关于JS获取HTML页面的BODY的高度全部的内容,包括:JS获取HTML页面的BODY的高度、js获取页面宽度和高度然后把值传给DIV、JS怎么获取div(高度和宽度都已设置百分比,继承父级)的height并应用于该div的line-height;等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)