1

我想知道如何在不同的 li 中获取每个图像的宽度(许多宽度),然后通过 jQuery 将该宽度返回给每个图像。

所有图像都有不同的宽度。

感谢您的帮助。

4

1 回答 1

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

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

   // OR

  var width = this.clientWidth;

  // to set that width to image try

  $(this).attr('width', width);

   // according to comment: how to assign width to parent li

   $(this).parent('li').css('width', width + 'px');
});
于 2013-02-18T17:13:58.973 回答