【发布时间】:2009-12-09 20:20:14
【问题描述】:
$(document).ready(function() {
var pic = $(".pic");
// need to remove these in of case img-element has set width and height
$(".pic").each(function() {
var $this = $(this);
$this.css({width: 'auto', height: 'auto'});
var pic_real_width = $this.width();
var pic_real_height = $this.height();
if(pic_real_width<100){
$(".pic").css("display","none");
}
});
});
我需要它来检查 .pic 类的所有图像的高度(它已经这样做了),然后将 display:none 添加到具有一定尺寸的图像。 (例如,如果 img 的宽度小于 100 像素,则不应显示)
【问题讨论】:
-
你5分钟前不是问过同样的问题吗? stackoverflow.com/questions/1873419/jquery-get-height-width
-
真的很像,这个是指代码的if。