Javascript 如何使行div中的所有div高度与行的第一个子行的高度相似

Javascript 如何使行div中的所有div高度与行的第一个子行的高度相似,javascript,Javascript,我想将行内的所有div更改为与行2的第一个子级的高度相似,如果类位于行外,div高度将自动更改,不会更改。我的代码中有什么问题?有人能解释一下吗?我不想从css中更改它 Jquery更容易。。我会这样做吗 // For each .box element $('.box').each(function() { // Set up the variables var $this = $(this), w = $this.find('img').wid

我想将行内的所有div更改为与
行2的第一个子级的高度相似,如果类位于行外,div高度将自动更改,不会更改。我的代码中有什么问题?有人能解释一下吗?我不想从css中更改它


Jquery更容易。。我会这样做吗

      // For each .box element
  $('.box').each(function() {
    // Set up the variables
    var $this = $(this),
        w = $this.find('img').width(), // Width of the image inside .box
        h = $this.find('img').height(); // Height of the image inside .box
    $this.width(w).height(h); // Set width and height of .box to match image
  });

所有块高度相同的变量()


你的html呢?html更新@br3这是一个错误的例子还是你的html中确实有几个
row2
.row2{clear:all;min height:auto;}
没有jquery请我想要JSBAutiful,但不起作用你能给我完整的代码吗
<div class="main"><div class="row2"><div class="lg">xfghjgjgx</div><div class="lg-in">xfgvcbvx</div></div>
<div class="row2"><div class="lg-in">xfghjgjgx</div><div class="lg">xfgvcbvx</div></div> 
      // For each .box element
  $('.box').each(function() {
    // Set up the variables
    var $this = $(this),
        w = $this.find('img').width(), // Width of the image inside .box
        h = $this.find('img').height(); // Height of the image inside .box
    $this.width(w).height(h); // Set width and height of .box to match image
  });
var classes = ["lg", "lg-in", "md"];
var requiredHeight = window.getComputedStyle(document.querySelector(".row2 .lg")).height;

classes.forEach(function(cls) {
    document.querySelectorAll("." + cls).forEach(function(item) {
        item.style.height = requiredHeight;
    });
});