栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

HTML元素(div)的全高,包括边框,内边距和边距?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

HTML元素(div)的全高,包括边框,内边距和边距?

如果可以使用jQuery:

$('#divId').outerHeight(true) // gives with margins.

对于香草javascript,您需要编写更多内容(像往常一样…):

function Dimension(elmID) {    var elmHeight, elmMargin, elm = document.getElementById(elmID);    if(document.all) {// IE        elmHeight = elm.currentStyle.height;        elmMargin = parseInt(elm.currentStyle.marginTop, 10) + parseInt(elm.currentStyle.marginBottom, 10) + "px";    } else {// Mozilla        elmHeight = document.defaultView.getComputedStyle(elm, '').getPropertyValue('height');        elmMargin = parseInt(document.defaultView.getComputedStyle(elm, '').getPropertyValue('margin-top')) + parseInt(document.defaultView.getComputedStyle(elm, '').getPropertyValue('margin-bottom')) + "px";    }    return (elmHeight+elmMargin);}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/575761.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号