gpt4 book ai didi

jQuery if 高度

转载 作者:行者123 更新时间:2023-12-01 06:17:44 28 4
gpt4 key购买 nike

我有几个带有“priceText”类的 div,我试图实现如果 div.priceText 高度小于 100px,则隐藏 this div 中的图像。

我无法让它工作。我已成功隐藏所有 .priceText div 上的所有 图像,如果其中一个 .priceText div 的高度小于 100 像素,但我只需要隐藏该图像即可在这个 div 中女巫小于 100px。

所以我未完成的代码:

$(".priceText").each(function() {

var $minHeight = 100;
var $priceHeight = $('.priceText').height();

if ( $priceHeight < $minHeight) {
$("img", this).remove();
}

});

最佳答案

我会这样做:

$(".priceText").each(function() {

var $minHeight = 100;
//you need the height of the div you are currently iterating on: use this
if ( $(this).height() < $minHeight) {
//find the img in this div and hide it
$(this).find('img').remove();
}

});

关于jQuery if 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6535690/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com