[英]How can I count the total width of many images in a div?
我有一个像这样的div元素:
<div id="test">
<img src="..."/>
<img src="..."/>
<img src="..."/>
<img src="..."/>
</div>
我要做的是首先使所有图像具有相同的高度,然后计算其新宽度的总和。 我尝试了这个:
window.onload = function() {
var width = $(window).width(), totalwidth=0;
$('#test img').height('200px');
$("#test").each(function() {
totalwidth += $("#test img").attr("width");
});
alert(totalwidth);
}
但是警报返回NaN
。 我该怎么办 ?
尝试
$("#test img").each(function() {
totalwidth += $(this).width();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.