2013-02-12 60 views
0
<!DOCTYPE html> 
<html> 
<head> 
    <title>Test IE8 pre calc</title> 
</head> 
<body> 

<div id='inserthere'></div> 
<p id="dump"></p> 
<p id="dump2"></p> 
</body> 

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 

<script> 
    $(function() { 
    var t = "<table style='white-space: pre;'><tr><td>abc def\nghi</td></tr></table>"; 

    $("#inserthere").append($(t)); 
    $("#dump").text($("tr").height()); 

    window.setTimeout(function() { 
     $("#dump2").text($("tr").height()); 
    }, 0); 
    }); 
</script> 
</html> 

在上面的代碼中,我在運行時向DOM插入一個表。該表使用'pre'空格規則進行格式化。異步IE8/jQuery錶行高計算

如果包含多行td的行的height()是在插入IE8錯誤地報告單行(21像素)的相同調用中計算的。如果同一個調用異步進行,IE8會正確報告兩行(40像素)。

IE9/10/Safari/Chrome/Firefox都很好。

+0

結束之前''有'

',請嘗試刪除它。 – Flauwekeul2013-02-12 21:32:41

+0

聽起來我好像IE8根本不會渲染速度夠快,儘管您似乎已經找到了解決方案。 – 2013-02-12 21:37:58

+0

@Flauwekeul - 斑點。例如固定 - 但可悲的是不是問題。 – ianhk 2013-02-12 21:45:09

回答

0

我還沒找到工作 - 所以答案是不要這樣做。一旦回車換成<br>,白色空間'nowrap'就會起作用。