jqueryif高度
我有几个div类为“priceText”,我正在尝试实现这一点,如果div.priceText高度小于100px,则在这个div中隐藏图像 我不能让它工作。如果其中一个.priceText div中的高度小于100px,我已设法隐藏所有图像。priceText div,但我只需要隐藏该div中的图像,该div小于100px 因此,我未完成的代码: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 =
$(".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();
}
});
Changevar$priceHeight=$('.priceText').height()
tovar$priceHeight=$(this.height()代码>
按照您的方式,它试图获取具有priceText类的所有元素的高度,而不是您当前引用的元素的高度。Changevar$priceHeight=$('.priceText').height()
tovar$priceHeight=$(this.height()代码>
按照您的方式,它正在尝试使用priceText类获取所有元素的高度,而不是您当前引用的元素。为什么在变量前面加上$
?不要那样做。尤其不要对不包含jQuery对象的变量使用$
前缀!为什么在VAR前面加上$
?不要那样做。尤其不要对不包含jQuery对象的变量使用$
前缀!这是正确的,但是$(“img”,This).remove();删除div和所有图像!不是真的,尼古拉<代码>这是上下文。请参见此处:这是正确的,但是$(“img”,This).remove();删除div和所有图像!不是真的,尼古拉<代码>这是上下文。请看这里: