【问题标题】:JQuery height conditionjQuery高度条件
【发布时间】: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 像素,则不应显示)

【问题讨论】:

标签: jquery css height width


【解决方案1】:

这应该可以解决问题:

$(document).ready(function() {
    // 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){
            $this.css("display","none");
        }
    });
 });

您再次引用集合而不是具体元素

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-19
    • 1970-01-01
    • 1970-01-01
    • 2012-05-20
    相关资源
    最近更新 更多