Javascript 如何读取html中所有子项的宽度?
我想编写一个JavaScript jQuery函数来读取每个child和childrens child的宽度,从而从一个I.e.div元素中获得所有child和childrens child的最大宽度 以下是我迄今为止的代码:Javascript 如何读取html中所有子项的宽度?,javascript,jquery,html,css,width,Javascript,Jquery,Html,Css,Width,我想编写一个JavaScript jQuery函数来读取每个child和childrens child的宽度,从而从一个I.e.div元素中获得所有child和childrens child的最大宽度 以下是我迄今为止的代码: function setBodyMinWidth(name){ var max = 0; $(name).find('*').each(fucntion(){ var width = $(this).outerWidth(true); if (width
function setBodyMinWidth(name){
var max = 0;
$(name).find('*').each(fucntion(){
var width = $(this).outerWidth(true);
if (width > max){
max = width;
}
});
$("body").css("minWidth", max+"px");
但它似乎不起作用。
我的问题是,在我的网站上我的浮动:对-如果浏览器的wndow太小,则内容超过页面内容。
我的网页正在建设中,如果你需要一些源代码,请随意看看
标记:
<body>
<div class=one >content1</div>
<div class=two >content2</div>
</body>
js
.one {width: 50px;}
.two {width: 70px;}
var max = 0;
$('body').find('div').each(function(){
var width = $(this).outerWidth(true);
if (width > max){
max = width;
};
});
alert(max);
$("body").css("minWidth", max+"px");