我不得不求助於此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