窗口刷新的javascript问题

时间:2014-12-08 07:40:04

标签: javascript

var newdiv, parent = $("#tuples");

for (i = 0; i < 10; i++) {
    parent.append("<div></div>");
    newdiv=parent.children().eq(index+i); 
    newdiv.css("display", "inline");
    newdiv.css("float", "left");

    newdiv.css("width", width + "px");
    newdiv.css("margin-right", "5px");
    newdiv.css("margin-left", "5px");
} 

child = parent.children();

for (i = 0; i < 10; i++) {
    newdiv = child.eq(i + index); 
    x.appendTo(newdiv);
    x = x.clone(); // here x is the whole node inside each new div
} 

//here change the attributes and images in the new divs
for (i = 0 + index; i < (10 + index); i++)
    child[i].setAttribute("index", i.toString());

代码运行良好,除了添加的新div显示在父级下方大约四分之一秒,然后浏览器水平重置它们看起来很奇怪,因为它看起来像窗口闪烁。但是,如果我在添加div之后发出警报,然后按ok键进入该警报,那么新div中的属性将被更改而不会出现任何闪烁;在这种情况下,div直接水平添加(首先不是垂直添加)

我认为让我们在添加div之后延迟然后更改属性,但这并没有解决问题。我认为浏览器不会在添加div之后更新窗口或刷新。有没有方法将添加的内容刷新到html?

0 个答案:

没有答案