Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何读取html中所有子项的宽度?_Javascript_Jquery_Html_Css_Width - Fatal编程技术网

Javascript 如何读取html中所有子项的宽度?

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

我想编写一个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 > 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");