我想用 jquery 将许多元素 (figcaption) 尺寸更改为 img 尺寸 请帮助我
var width = $("div[caption='true'] img").attr("width");
var height = $("div[caption='true'] img").attr("height");
$("div[caption='true'] figcaption").css("width",width);
$("div[caption='true'] figcaption").css("height",height);
最佳答案
试试这个:
$(function() {
$("div[caption='true']").each(function() {
var $this = $(this);
var image = $this.find('img')
var width = image.width();
var height = image.height();
$this.find('figcaption').width(width).height(height);
});
});
jsFiddle:http://jsfiddle.net/8ge1wvpt/11/
关于javascript - 改变元素的尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27545860/