如何更改div内所有图像的高度?
我有
$('.images img').each(function() {
$('img').attr('height', element.parent().attr('imgheight'));
});
<div imgheight="300px" class="images">
<img src=" http://www.yu51a5.com/wp-content/uploads/2015/01/goldenhorseman.jpg " />
<img src=" http://www.yu51a5.com/wp-content/uploads/2015/01/bronze-horseman.jpg " />
</div>
它似乎没有做任何事情 - 请参阅 https://jsfiddle.net/yu51a5/527gn64n/4/ 。如何让它发挥作用?
我不能使用“height=100%”,因为通常这些图像带有标题,因此图像应该比 div 短。
最佳答案
您尚未定义元素
。从每个函数内部访问节点。
$('.images img').each(function(i, node) {
$('img').attr('height', $(node).parent().attr('imgheight'));
});
关于javascript - 如何改变div内所有图像的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36296622/