Jquery 每个列表项的增量
我试图增加每个列表项的Jquery 每个列表项的增量,jquery,html,Jquery,Html,我试图增加每个列表项的z-index 这就是我迄今为止所尝试的: var photos = $('ul'); photos.each(function () { var photos = $(this).children(); var photosLen = photos.length; if (photosLen > 1) { photos.parent().addClass('album'); v
z-index
这就是我迄今为止所尝试的:
var photos = $('ul');
photos.each(function () {
var photos = $(this).children();
var photosLen = photos.length;
if (photosLen > 1) {
photos.parent().addClass('album');
var i = 0;
while (i < photosLen) {
$(this).children().css({
'z-index': i
});
}
}
});
因为您已经在使用jQuery,所以代码可以简单地
if (photosLen > 1) {
photos.each(function(i) {
$(this).css('zIndex', i);
})
.parent()
.addClass('album');
}
请注意
each()
和z-index
属性的camelCase语法,因为您已经在使用jQuery,所以代码可以简单地
if (photosLen > 1) {
photos.each(function(i) {
$(this).css('zIndex', i);
})
.parent()
.addClass('album');
}
注意
each()
和z-index
属性的camelCase语法您忘记了在代码中增加i
的值: while (i < photosLen) {
$(this).children().css({
'z-index': i
});
i++;
}
while(i
您忘记在代码中增加i
的值: while (i < photosLen) {
$(this).children().css({
'z-index': i
});
i++;
}
while(i
不是photos.parent()
和$(这个)
?哈哈,不是。。。我需要更仔细地命名变量……真的吗?您不认为$(this).children().parent()
与$(this)
?:)相同是不是photos.parent()
和$(这个)
一样?哈哈,不是。。。我需要更仔细地命名变量……真的吗?您不认为$(this).children().parent()
与$(this)
?:)相同