87,917
社区成员
发帖
与我相关
我的任务
分享
$(document).ready(function () {
$('#tab1 img').each(function () {
AutoResizeImage(this);
})
});
function AutoResizeImage(objImg) {
var img = new Image();
img.src = objImg.src;
// alert(img.src);
w = img.offsetWidth;
h = img.offsetHeight;
alert(w);
alert(h);
}
<table id="tab1">
<tr>
<td>
<img src="img1.jpg" />
</td>
</tr>
<tr>
<td>
<img src="img2.jpg" />
</td>
</tr>
<tr>
<td>
<img src="img3.jpg" />
</td>
</tr>
</table>
$(document).ready(function () {
$('#tab1 img').each(function () {
alert("width:" + $(this).width() + " height:" + $(this).height());
})
});
$(document).ready(function () {
$('#tab1 img').each(function () {
AutoResizeImage(this);
})
});
function AutoResizeImage(objImg) {
var img = new Image();
img.src = objImg.src;
document.body.appendChild(img);
// alert(img.src);
w = img.offsetWidth;
h = img.offsetHeight;
alert(w);
alert(h);
}
img没放dom里面啊