我不得不求助于此bodge设置div01-05不同的高度,以div11-15 :(迭代的div阵列
var maxheight = divheight;
var dayofweek = <?echo date("w",strtotime($today));?>;
var heightoffset = (2 - dayofweek) * 40;
var days = jQuery('div.day01, div.day02, div.day03, div.day04, div.day05');
for (i=0; i<days.length; i++){
var hh = jQuery(days[i]).prop("scrollHeight");
if (hh > maxheight) {
maxheight = hh;
};
jQuery(days[i]).height(divheight+heightoffset);
};
var days = jQuery('div.day11, div.day12, div.day13, div.day14, div.day15');
for (i=0; i<days.length; i++){
var hh = jQuery(days[i]).prop("scrollHeight");
if (hh > maxheight) {
maxheight = hh;
};
jQuery(days[i]).height(divheight-heightoffset);
};
//Back to full array for further processing
var days = jQuery('div.day01, div.day02, div.day03, div.day04, div.day05, div.day11, div.day12, div.day13, div.day14, div.day15');
会有人请把我赶出痛苦和秀我如何迭代所有的div并做一个有条件的设置高度
一个警告是,PHP是greating的div和div.day01 -04可能不存在取决于一天的一天div.day05总是会和so div div day11-15
关于 Simon
最终代码的结果(已经更正为使用ID而不是类:)
jQuery('div[id^="day"]').each(function() {
var hh = jQuery(this).prop("scrollHeight");
if (hh > maxheight) {maxheight = hh;};
var cn = jQuery(this).attr('id').split(" ")[0]; // Since PHP is creating these classes, we can safely assume "day" will always be the first.
var num = parseInt(cn.slice(-2),10); // extract the last two characters and convert to an integer
if (num >=1 && num <= 5) {
jQuery(this).height(divheight+heightoffset);
}else if(num >=10 && num <= 15){
jQuery(this).height(divheight-heightoffset);
}
});
'div's可能包含其他类,所以你应该检查,看看是否div包含类'/ day \ d * /'第一个。 –
这就是为什么我应该使用ID代替。:-) – Blazemonger
重新您的$ div每个函数 - 如何我改变这个只是迭代div的01-15,因为我还有其他的div,感谢在课堂上的头像/编号错误 - 我会明确地避开它,但会纠正:) – SimpleSi