简体   繁体   English

添加到其DOM ie8之后,HTML表不会重绘

[英]Html table does not redraw after adding to its DOM ie8

IE bugs out on me with a large table by not redrawing the table when I add input's to it using jquery. 当我使用jquery向其中添加输入时,IE不会重绘表,从而使我无法使用大表。 It forces a redraw/update when I scroll the table up or down but otherwise it doesnt render the input properly. 当我向上或向下滚动表格时,它会强制重新绘制/更新,但否则无法正确呈现输入。

<div style="overflow: auto;">
   <table>
       <tbody>
           /// lots of rows
       </tbody>
   </table>
</div>

and the javascript snippet : 和javascript代码段:

input = $(document.createElement("input"));
input.attr("type", "text");
input.attr("value", $.trim(div.html())); 
TD.prepend(input);

This works just fine in firefox but refuses to behave in IE8. 这在Firefox中工作得很好,但是在IE8中却表现不佳。 A way to fix is to force a redraw but I can't seem to find a way to do that. 解决方法是强制重画,但我似乎找不到解决办法。

I think ie8 is rendering in quirks mode but it doesnt work in either ie8 or quirks mode. 我认为ie8在怪异模式下渲染,但在ie8或怪异模式下均不起作用。

[Edit] [编辑]

function forceIERedraw() {
    if ($.browser.msie) {
        obj = getThing();
        obj.scrollTop = obj.scrollTop - 1;
        obj.scrollTop = obj.scrollTop + 1;
    }
}

This works but of course makes the screen shake ever so slightly. 这行得通,但是当然会使屏幕抖动得如此轻微。 Horribly hacked but at least you can see things that I add to the dom. 骇人听闻,但至少您可以看到我添加到dom中的内容。

hiding and showing the body usually works with issues like yours: 隐藏和显示身体通常可以解决像您这样的问题:

input = $(document.createElement("input"));
input.attr("type", "text");
input.attr("value", $.trim(div.html())); 
TD.prepend(input);
document.body.style.display = 'none';
document.body.style.display = 'block';

Today I encountered somewhat similar problem, solved it by just rewriting the whole html of the div again. 今天,我遇到了类似的问题,只需再次重写div的整个html即可解决。 Later I found your question here... 后来我在这里找到你的问题...

Lets say your div had an id stupiddiv 假设您的div有一个id stupiddiv
Now you do something like this : 现在,您可以执行以下操作:
$('#stupiddiv').html($('#stupiddiv').html());
after appending the table and all... That would just work if you had small tables, but with huge tables, I guess it would take performance toll... 追加表格和所有表格之后...如果您有小表格,但有大表格,那将起作用,我想这会影响性能...

Turns out the problem was specific to the website im working on (10 years old at that.) and rendering in ie quirks mode. 事实证明,该问题是特定于正在运行的网站(当时已经有10年历史了)并以怪癖模式呈现的。 Basically the whole thing was a mess and this was a side effect of various other problems on the page. 基本上,整个过程都是一团糟,这是页面上其他各种问题的副作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM