我有一个Web应用程序屏幕,其中包含许多动态创建的JQuery UI手风琴。我正在循环传入的JSON字符串,并按如下方式动态创建手风琴。
for (i in json.panels) {
var accordionName = json.panels[i].panelName;
var isExpanded = json.panels[i].expand;
var activeProperty = (isExpanded) ? 0 : false;
var accordElemId = "accordion_"+i;
var accordDiv = '<div id="' + accordElemId + '"></div>';
var accordion = $("#"+accordElemId );
var startTime = new Date().getTime();
accordion.accordion({
collapsible: true,
heightStyle: "content",
active: activeProperty,
animated : false
});
var endTime = new Date().getTime();
console.log("Time for "+accordionName+"="+(endTime - startTime));
}
然后我比较了在IE8和IE10中创建每个手风琴的时间
在IE8中我发现它真的很慢,当我浏览页面时,性能会不断下降。 请看下面的数字,时间以毫秒为单位。1)
LOG: ----------------------------start -------------------------------------
LOG: Time for Patient Address = 16
LOG: Time for Current Legal Status = 32
LOG: Time for Alerts and Risk Factors = 0
LOG: Time for Current Wards/Programs = 16
LOG: Time for Open Orders = 0
LOG: Time for RAI-MH Form = 0
LOG: Time for RAI = 16
LOG: Time for OCAN-C = 31
LOG: Time for LD = 0
LOG: --- Diff create ajaxURL = 0
LOG: ----------------------------end -------------------------------------
2)
LOG: ----------------------------start -------------------------------------
LOG: Time for Patient Address = 16
LOG: Time for Current Legal Status = 47
LOG: Time for Alerts and Risk Factors = 32
LOG: Time for Current Wards/Programs = 16
LOG: Time for Open Orders = 15
LOG: Time for RAI-MH Form = 110
LOG: Time for RAI = 140
LOG: Time for OCAN-C = 141
LOG: Time for LD = 31
LOG: --- Diff create ajaxURL = 0
LOG: ----------------------------end -------------------------------------
3)
LOG: ----------------------------start -------------------------------------
LOG: Time for Patient Address = 62
LOG: Time for Current Legal Status = 485
LOG: Time for Alerts and Risk Factors = 15
LOG: Time for Current Wards/Programs = 219
LOG: Time for Open Orders = 391
LOG: Time for RAI-MH Form = 62
LOG: Time for RAI = 250
LOG: Time for OCAN-C = 391
LOG: Time for LD = 110
LOG: --- Diff create ajaxURL = 0
LOG: ----------------------------end -------------------------------------
然后我尝试了IE 10,它超级快,并且与性能一致
----------------------------start -------------------------------------
Time for Patient Address = 7
Time for Current Legal Status = 5
Time for Alerts and Risk Factors = 5
Time for Current Wards/Programs = 6
Time for Open Orders = 6
Time for RAI-MH Form = 6
Time for RAI = 4
Time for OCAN-C = 4
Time for LD = 4
--- Diff create ajaxURL = 0
----------------------------end ------------------------------------
你们对此有什么想法吗?感谢你的帮助
谢谢, Keth