我想在 if 子句中获取结果的长度,然后将其写入输入隐藏元素中。
代码:
<script type="text/javascript">
$(document).ready(function(){
var imgs = document.getElementById("images").getElementsByTagName("img");
var imgSrcs = [];
for (var i = 0; i < imgs.length; i++) {
$('#loaderimg').html(imgSrcs += getImgSize(imgs[i].src));
}
function getImgSize(imgSrc){
var newImg = new Image();
newImg.src = imgSrc;
var height = newImg.height;
var width = newImg.width;
p = $(newImg).ready(function(){
return {width: newImg.width, height: newImg.height};
});
// return (p[0]['width']+" "+p[0]['height']);
if(p[0]['width'] >= 100){
return ('<img src="'+imgSrc+'" id="'+i+'" width="100" style="max-height:150px;">');
}else{
return ('');
}
}
});
</script>