我正在使用jQuery 1.7.1編碼這種或那種方式是否有性能優勢?
我想寫這個代碼的可讀性以及性能。在以下兩種情況下,哪一種表現更好,爲什麼?
// BLOCK ONE
var DivHeight = 0;
$(".PC_SeriesDiv").each(function() {
var ThisDivHeight = $(this).height();
if (ThisDivHeight > DivHeight) {
DivHeight = ThisDivHeight;
}
});
DivHeight = DivHeight + "px";
$(".PC_SeriesDiv").animate({height: DivHeight}, 250);
// BLOCK TWO
var DivHeight = 0;
var PC_SeriesDiv = $(".PC_SeriesDiv");
PC_SeriesDiv.each(function() {
var ThisDivHeight = $(this).height();
if (ThisDivHeight > DivHeight) {
DivHeight = ThisDivHeight;
}
});
DivHeight = DivHeight + "px";
PC_SeriesDiv.animate({height: DivHeight}, 250);
我的問題真的可以歸結爲是否有這樣做的任何好處:
var PC_SeriesDiv = $(".PC_SeriesDiv");
建議將不勝感激。謝謝!
感謝您的建議和示例。我完全實現了這一切。 – 2012-02-28 17:03:18