2009-04-20 32 views
0

我有幾個CSS選擇器這樣的:我怎麼能強制Internet Explorer以應用CSS樣式

table.SearchCustomerResults > thead > tr > th[sortOrder="0"] {} 
table.SearchCustomerResults > thead > tr > th[sortOrder="1"] {} 

然後我爲每一個在JavaScript中細胞中將sortOrder擴展屬性。但是,在我移動光標之前,瀏覽器(IE7,也許是其他的)中看不到變化的樣式。我如何強制樣式重新評估?

編輯:我沒有使用原來所說的IE6,但IE7。但問題仍然存在。

回答

2

有各種hack-y方法來強制重新渲染。 script.aculo.us有一個名爲forceRerendering(自然)方法,看起來像這樣:

someElement.appendChild(document.createTextNode(' ')); 
someElement.removeChild(someElement.lastChild); 

這應該在這種情況下工作了。

1

IE6不支持屬性或子選擇器,所以這根本不應該工作。你在使用ie7-js嗎?


OK,我現在看到。這看起來像IE中的一個錯誤(使用divtitle,對於thsortOrder有同樣的問題)。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html> 
    <head> 
    <style> 
     th[sortOrder="0"] {color:red} 
     th[sortOrder="1"] {color:blue} 
    </style> 
    <script> 
     function changeSortOrder() { 
     // swap the orders so that blue is actually red and vice versa 
     document.getElementById("hdr0").setAttribute("sortOrder","1"); 
     document.getElementById("hdr1").setAttribute("sortOrder","0"); 
     //document.getElementById("hdr0").innerHTML += ""; 
     //document.getElementById("hdr1").innerHTML += ""; 
     } 
    </script> 
    </head> 
    <body onload="changeSortOrder()"> 
    <table class="SearchCustomerResults"> 
     <thead><tr> 
     <th sortOrder="0" id="hdr0">red</th> 
     <th sortOrder="1" id="hdr1">blue</th> 
     </tr></thead> 
    </table> 
    </body> 
</html> 

修飾innerHTML的線條似乎解決的bug。雖然在Google上找不到任何引用。

+0

對不起,我是用IE7的。但問題仍然存在 – erikkallen 2009-04-20 11:52:37

0

我有類似的問題:插入新的div後沒有應用保證金。
下一個代碼幫助:
   的setTimeout(函數(){。newDiv.addClass( 'tratata')removeClass( 'tratata');},0);     // jquery syntax