jquery height / width if语句不工作 [英] jquery height/width if statement not working

查看:147
本文介绍了jquery height / width if语句不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$(window).load(function () {

    var $imgs = $('.boxInner img');

    $imgs.each(function () {
        var w = $(this).clientWidth;
        var h = $(this).clientHeight;

        if (w < h) { $(this).css("display","none"); };
    });
});

我试图用这么多不同的方式写这个文件没有用。基本上,只是看图片的宽度和高度。如果高度大于宽度,则显示为none。有人请帮助我想出这个。应该这么简单。

I've tried to write this in so many different ways to no avail. Basically, just look at the picture width and height. If the height is greater than the width turn the display to none. Somebody please help me figure this out. Should be so simple.

推荐答案

使用dom对象及其api:

either use the dom objects and its api:

$imgs.each(function () {
    var w = this.clientWidth;
    var h = this.clientHeight;

    if (w < h) { $(this).css("display","none"); };
});

或使用jQuery对象及其api:

or use jQuery objects and its api:

$imgs.each(function () {
    var w = $(this).width();
    var h = $(this).height();

    if (w < h) { $(this).css("display","none"); };
});

这篇关于jquery height / width if语句不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆