我被告知不要for...in在JavaScript中使用数组.为什么不?
我有一个预订引擎,在IE7中相当缓慢.它基于ajaxified和hash/window onchange.共有5个步骤.我遇到的主要问题是第2步在IE中非常慢.
当用户登陆步骤2时,发出ajax请求以使用web服务提取数据以显示酒店房间.酒店客房按主要房型和内部更具体类型划分.应用于酒店房间的JS功能包括:
所有这一切导致着名:

显然原因是在IE中的特定时间内有太多的脚本语句按顺序执行.
我基本上需要重构我的代码并对其进行优化,以便在函数调用之间存在延迟.
我在执行ajax请求后注入HTML的方式是:
734 $( o.html ).appendTo( el )
Run Code Online (Sandbox Code Playgroud)
o.html是对html从此处派生的JSON对象属性的引用.
然后,下面的代码运行:
setTimeout(function () {
$('#roomz .room-accordion').each(function () {
$(this).accordion({
header: 'h2.new-heading',
autoheight: false,
clearStyle: true,
collapsible: true,
change: function (event, ui) {
window.ui = ui;
// if it hasnt been quickflipped/subnest accordioned, do it
if (!$(ui.newContent).data('enabled')) {
$('.room-rates', ui.newContent).each(function () {
$(this).accordion({
header: 'h4.rate-name',
autoheight: false,
active: 0,
clearStyle: …Run Code Online (Sandbox Code Playgroud) javascript ×2
arrays ×1
dom ×1
for-loop ×1
iteration ×1
loops ×1
optimization ×1
refactoring ×1