使用.each()JQuery添加到现有值

Cec*_*ore 2 each jquery loops function

我有一个.each()函数来测量类中每个图像的宽度.item.我需要测量所有宽度,然后将其添加到变量中.然后需要将该变量传递出函数.下面这个功能只完成了一半,我只是不知道如何完成它.

任何帮助非常感谢.

$('.item img').each(function () {

    var i = $(this).width();

});

$('.overview').css('width', i);
Run Code Online (Sandbox Code Playgroud)

472*_*084 9

var i = 0;

$('.item img').each(function () {

    i = i + $(this).width();

});

$('.overview').css('width', i);
Run Code Online (Sandbox Code Playgroud)