Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jqueryif高度_Jquery_If Statement_Each - Fatal编程技术网

jqueryif高度

jqueryif高度,jquery,if-statement,each,Jquery,If Statement,Each,我有几个div类为“priceText”,我正在尝试实现这一点,如果div.priceText高度小于100px,则在这个div中隐藏图像 我不能让它工作。如果其中一个.priceText div中的高度小于100px,我已设法隐藏所有图像。priceText div,但我只需要隐藏该div中的图像,该div小于100px 因此,我未完成的代码: $(".priceText").each(function() { var $minHeight = 100; var $priceHeight =

我有几个div类为“priceText”,我正在尝试实现这一点,如果div.priceText高度小于100px,则在这个div中隐藏图像

我不能让它工作。如果其中一个.priceText div中的高度小于100px,我已设法隐藏所有图像。priceText div,但我只需要隐藏该div中的图像,该div小于100px

因此,我未完成的代码:

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

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

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

});
$(“.priceText”)。每个(函数(){
var$minHeight=100;
var$priceHeight=$('.priceText').height();
如果($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();
}

});
$(“.priceText”)。每个(函数(){
var$minHeight=100;
//您需要当前迭代的div的高度:使用
如果($(this).height()<$minHeight){
//在此分区中找到img并将其隐藏
$(this.find('img').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();
}

});
$(“.priceText”)。每个(函数(){
var$minHeight=100;
//您需要当前迭代的div的高度:使用
如果($(this).height()<$minHeight){
//在此分区中找到img并将其隐藏
$(this.find('img').remove();
}
});

Change
var$priceHeight=$('.priceText').height()
to
var$priceHeight=$(this.height()


按照您的方式,它试图获取具有priceText类的所有元素的高度,而不是您当前引用的元素的高度。

Change
var$priceHeight=$('.priceText').height()
to
var$priceHeight=$(this.height()


按照您的方式,它正在尝试使用priceText类获取所有元素的高度,而不是您当前引用的元素。

为什么在变量前面加上
$
?不要那样做。尤其不要对不包含jQuery对象的变量使用
$
前缀!为什么在VAR前面加上
$
?不要那样做。尤其不要对不包含jQuery对象的变量使用
$
前缀!这是正确的,但是$(“img”,This).remove();删除div和所有图像!不是真的,尼古拉<代码>这是上下文。请参见此处:这是正确的,但是$(“img”,This).remove();删除div和所有图像!不是真的,尼古拉<代码>这是上下文。请看这里: